about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-26T23·07+0300
committertazjin <tazjin@tvl.su>2022-09-03T21·55+0000
commit5ecf573dffc581e7842263f674ef43a66a2ba900 (patch)
tree07f6a5417236acef788ca85d357353e259877957
parent69d8f17a26db50e7b76297dbf588aafc23425c71 (diff)
feat(tvix/eval): add Value::to_closure r/4626
... same as the others

Change-Id: I9c8868388c10b0b6484c5bdd3799d801296c6979
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6292
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
-rw-r--r--tvix/eval/src/value/mod.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index 1210e0f9a7e9..f6583db5ab97 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -113,6 +113,17 @@ impl Value {
         }
     }
 
+    pub fn to_closure(self) -> EvalResult<Closure> {
+        match self {
+            Value::Closure(c) => Ok(c),
+            other => Err(ErrorKind::TypeError {
+                expected: "lambda",
+                actual: other.type_of(),
+            }
+            .into()),
+        }
+    }
+
     pub fn is_bool(&self) -> bool {
         matches!(self, Value::Bool(_))
     }