diff options
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 6e839798d4ac..1593ab19d3aa 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -524,6 +524,16 @@ impl<'a> Iterator for Iter<KeyValue<'a>> { } } +impl<'a> ExactSizeIterator for Iter<KeyValue<'a>> { + fn len(&self) -> usize { + match &self.0 { + KeyValue::Empty => 0, + KeyValue::KV { .. } => 2, + KeyValue::Map(inner) => inner.len(), + } + } +} + enum KeysInner<'a> { Empty, KV(IterKV), @@ -562,6 +572,16 @@ impl<'a> IntoIterator for &'a NixAttrs { } } +impl<'a> ExactSizeIterator for Keys<'a> { + fn len(&self) -> usize { + match &self.0 { + KeysInner::Empty => 0, + KeysInner::KV(_) => 2, + KeysInner::Map(m) => m.len(), + } + } +} + /// Internal representation of an owning attrset iterator pub enum IntoIterRepr { Empty, |