feat(tvix/eval): add Value variants for strings & attrsets

Change-Id: Idebf663ab7fde3955aae50f635320f7eb6c353e8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6087
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2022-08-08 17:27:16 +03:00 committed by tazjin
parent ba03226e51
commit 2ed38a7cdb
4 changed files with 21 additions and 6 deletions

View file

@ -34,3 +34,9 @@ impl Display for NixAttrs {
f.write_str("}")
}
}
impl PartialEq for NixAttrs {
fn eq(&self, _other: &Self) -> bool {
todo!("attrset equality")
}
}

View file

@ -1,18 +1,23 @@
//! This module implements the backing representation of runtime
//! values in the Nix language.
use std::fmt::Display;
use crate::errors::{Error, EvalResult};
use std::rc::Rc;
mod attrs;
mod string;
#[derive(Clone, Copy, Debug, PartialEq)]
use crate::errors::{Error, EvalResult};
use attrs::NixAttrs;
use string::NixString;
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
Null,
Bool(bool),
Integer(i64),
Float(f64),
String(NixString),
Attrs(Rc<NixAttrs>),
}
impl Value {
@ -30,6 +35,8 @@ impl Value {
Value::Bool(_) => "bool",
Value::Integer(_) => "int",
Value::Float(_) => "float",
Value::String(_) => "string",
Value::Attrs(_) => "set",
}
}
@ -52,6 +59,8 @@ impl Display for Value {
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)),
Value::String(s) => s.fmt(f),
Value::Attrs(attrs) => attrs.fmt(f),
}
}
}

View file

@ -3,7 +3,7 @@ use std::fmt::Display;
/// This module implements Nix language strings and their different
/// backing implementations.
#[derive(Debug, Hash, PartialEq)]
#[derive(Clone, Debug, Hash, PartialEq)]
pub struct NixString(String);
impl Display for NixString {