diff options
Diffstat (limited to 'tvix/eval/src/value/list.rs')
-rw-r--r-- | tvix/eval/src/value/list.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs index 19415c0d557f..8563c2256f07 100644 --- a/tvix/eval/src/value/list.rs +++ b/tvix/eval/src/value/list.rs @@ -1,6 +1,8 @@ //! This module implements Nix lists. use std::fmt::Display; +use crate::errors::ErrorKind; + use super::Value; #[repr(transparent)] @@ -20,6 +22,12 @@ impl Display for NixList { } } +impl From<Vec<Value>> for NixList { + fn from(vs: Vec<Value>) -> Self { + Self(vs) + } +} + #[cfg(feature = "arbitrary")] mod arbitrary { use proptest::{ @@ -73,4 +81,19 @@ impl NixList { pub fn into_iter(self) -> std::vec::IntoIter<Value> { self.0.into_iter() } + + /// Compare `self` against `other` for equality using Nix equality semantics + pub fn nix_eq(&self, other: &Self) -> Result<bool, ErrorKind> { + if self.len() != other.len() { + return Ok(false); + } + + for (v1, v2) in self.iter().zip(other.iter()) { + if !v1.nix_eq(v2)? { + return Ok(false); + } + } + + Ok(true) + } } |