feat(tvix/eval): implement Display trait for Value enum

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>
This commit is contained in:
Vincent Ambo 2022-08-08 16:43:09 +03:00 committed by clbot
parent 0d2896519c
commit 3ed45caad1

View file

@ -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)),
}
}
}