about summary refs log tree commit diff
path: root/tvix/eval/src/value.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/value.rs')
-rw-r--r--tvix/eval/src/value.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/value.rs b/tvix/eval/src/value.rs
index cbfff55b49..842d561d67 100644
--- a/tvix/eval/src/value.rs
+++ b/tvix/eval/src/value.rs
@@ -1,6 +1,8 @@
 //! This module implements the backing representation of runtime
 //! values in the Nix language.
 
+use crate::errors::{Error, EvalResult};
+
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub enum Value {
     Null,
@@ -26,6 +28,16 @@ impl Value {
             Value::Float(_) => "float",
         }
     }
+
+    pub fn as_bool(self) -> EvalResult<bool> {
+        match self {
+            Value::Bool(b) => Ok(b),
+            other => Err(Error::TypeError {
+                expected: "bool",
+                actual: other.type_of(),
+            }),
+        }
+    }
 }
 
 #[derive(Clone, Copy, Debug, PartialEq)]