feat(tvix/eval): add module for attribute set implementations
Change-Id: I6002bd5e5596b93325dea6c862370ba5235c0f08 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6086 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
d26c097d1b
commit
ba03226e51
2 changed files with 37 additions and 0 deletions
36
tvix/eval/src/value/attrs.rs
Normal file
36
tvix/eval/src/value/attrs.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
/// This module implements Nix attribute sets. They have flexible
|
||||
/// backing implementations, as they are used in very versatile
|
||||
/// use-cases that are all exposed the same way in the language
|
||||
/// surface.
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::string::NixString;
|
||||
use super::Value;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum NixAttrs {
|
||||
Map(BTreeMap<NixString, Value>),
|
||||
KV { name: NixString, value: Value },
|
||||
}
|
||||
|
||||
impl Display for NixAttrs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("{ ")?;
|
||||
|
||||
match self {
|
||||
NixAttrs::KV { name, value } => {
|
||||
f.write_fmt(format_args!("name = \"{}\"; ", name))?;
|
||||
f.write_fmt(format_args!("value = {}; ", value))?;
|
||||
}
|
||||
|
||||
NixAttrs::Map(map) => {
|
||||
for (name, value) in map {
|
||||
f.write_fmt(format_args!("{} = {}; ", name, value))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
f.write_str("}")
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ use std::fmt::Display;
|
|||
|
||||
use crate::errors::{Error, EvalResult};
|
||||
|
||||
mod attrs;
|
||||
mod string;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
|
Loading…
Reference in a new issue