about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/value/mod.rs14
-rw-r--r--tvix/eval/src/value/string.rs4
2 files changed, 14 insertions, 4 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index ea0c89e6b6c4..56f8620d3a58 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -7,8 +7,8 @@ mod attrs;
 mod string;
 
 use crate::errors::{Error, EvalResult};
-use attrs::NixAttrs;
-use string::NixString;
+pub use attrs::NixAttrs;
+pub use string::NixString;
 
 #[derive(Clone, Debug, PartialEq)]
 pub enum Value {
@@ -49,6 +49,16 @@ impl Value {
             }),
         }
     }
+
+    pub fn as_string(self) -> EvalResult<NixString> {
+        match self {
+            Value::String(s) => Ok(s),
+            other => Err(Error::TypeError {
+                expected: "string",
+                actual: other.type_of(),
+            }),
+        }
+    }
 }
 
 impl Display for Value {
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs
index 7e6f5ecf3bd3..531bcf547b0b 100644
--- a/tvix/eval/src/value/string.rs
+++ b/tvix/eval/src/value/string.rs
@@ -3,8 +3,8 @@ use std::fmt::Display;
 /// This module implements Nix language strings and their different
 /// backing implementations.
 
-#[derive(Clone, Debug, Hash, PartialEq)]
-pub struct NixString(String);
+#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
+pub struct NixString(pub String);
 
 impl Display for NixString {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {