about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-08T13·43+0300
committerclbot <clbot@tvl.fyi>2022-08-12T14·12+0000
commit3ed45caad13bbe3133280d0934d9f0abd07a8c62 (patch)
treed9de488f81946b561f459dd104ca03c17e434ce5 /tvix
parent0d2896519cf8dae97da024912d93c37b3c3bba85 (diff)
feat(tvix/eval): implement Display trait for Value enum r/4418
This representation should match what the Nix REPL shows for result
values.

Change-Id: If3143d969fcdc123a6029e2aeb7bbd6ae51aeb71
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6082
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/value.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/eval/src/value.rs b/tvix/eval/src/value.rs
index 699c7de7bcdd..a4656b1b9cb7 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 std::fmt::Display;
+
 use crate::errors::{Error, EvalResult};
 
 #[derive(Clone, Copy, Debug, PartialEq)]
@@ -39,3 +41,15 @@ impl Value {
         }
     }
 }
+
+impl Display for Value {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            Value::Null => f.write_str("null"),
+            Value::Bool(true) => f.write_str("true"),
+            Value::Bool(false) => f.write_str("false"),
+            Value::Integer(num) => f.write_fmt(format_args!("{}", num)),
+            Value::Float(num) => f.write_fmt(format_args!("{}", num)),
+        }
+    }
+}