feat(tvix/eval): ExactSizeIterator for Iter<KeyValue<'a>> and Keys

Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: Ia373eb30d8516a056f1349f9011dee9816593d6f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7357
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Adam Joseph 2022-11-22 23:23:28 -08:00
parent c06840ff87
commit ff658006f0

View file

@ -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,