about summary refs log tree commit diff
path: root/tvix/eval/src/value/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-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 f6583db5ab97..eb23605bd0b2 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -80,6 +80,17 @@ impl Value {
         }
     }
 
+    pub fn as_str(&self) -> EvalResult<&str> {
+        match self {
+            Value::String(s) => Ok(s.as_str()),
+            other => Err(ErrorKind::TypeError {
+                expected: "string",
+                actual: other.type_of(),
+            }
+            .into()),
+        }
+    }
+
     pub fn to_string(self) -> EvalResult<NixString> {
         match self {
             Value::String(s) => Ok(s),