From 3ed45caad13bbe3133280d0934d9f0abd07a8c62 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 8 Aug 2022 16:43:09 +0300 Subject: 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 Reviewed-by: grfn --- tvix/eval/src/value.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tvix/eval/src') 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)), + } + } +} -- cgit 1.4.1