about summary refs log tree commit diff
path: root/tvix/eval/src/value/string.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/value/string.rs')
-rw-r--r--tvix/eval/src/value/string.rs34
1 files changed, 29 insertions, 5 deletions
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs
index d4776caea4..47661e03ad 100644
--- a/tvix/eval/src/value/string.rs
+++ b/tvix/eval/src/value/string.rs
@@ -4,16 +4,40 @@ use std::fmt::Display;
 /// backing implementations.
 
 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
-pub struct NixString(pub String);
+pub enum NixString {
+    Static(&'static str),
+    Heap(String),
+}
 
 impl Display for NixString {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        f.write_str(self.0.as_str())
+        match self {
+            NixString::Static(s) => f.write_str(s),
+            NixString::Heap(s) => f.write_str(s),
+        }
+    }
+}
+
+impl From<&'static str> for NixString {
+    fn from(s: &'static str) -> Self {
+        NixString::Static(s)
     }
 }
 
-impl From<&str> for NixString {
-    fn from(s: &str) -> Self {
-        NixString(s.to_string())
+impl From<String> for NixString {
+    fn from(s: String) -> Self {
+        NixString::Heap(s)
+    }
+}
+
+impl NixString {
+    pub const NAME: Self = NixString::Static("name");
+    pub const VALUE: Self = NixString::Static("value");
+
+    pub fn as_str(&self) -> &str {
+        match self {
+            NixString::Static(s) => s,
+            NixString::Heap(s) => s,
+        }
     }
 }