diff --git a/crates/nu-protocol/src/value/record.rs b/crates/nu-protocol/src/value/record.rs index 6d4f3b3513..6aedbc5755 100644 --- a/crates/nu-protocol/src/value/record.rs +++ b/crates/nu-protocol/src/value/record.rs @@ -216,6 +216,12 @@ impl Record { } } + pub fn into_columns(self) -> IntoColumns { + IntoColumns { + iter: self.inner.into_iter(), + } + } + pub fn values(&self) -> Values { Values { iter: self.inner.iter(), @@ -385,6 +391,10 @@ impl Iterator for IntoIter { fn next(&mut self) -> Option { self.iter.next() } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } } impl DoubleEndedIterator for IntoIter { @@ -421,6 +431,10 @@ impl<'a> Iterator for Iter<'a> { fn next(&mut self) -> Option { self.iter.next().map(|(col, val): &(_, _)| (col, val)) } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } } impl<'a> DoubleEndedIterator for Iter<'a> { @@ -457,6 +471,10 @@ impl<'a> Iterator for IterMut<'a> { fn next(&mut self) -> Option { self.iter.next().map(|(col, val)| (&*col, val)) } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } } impl<'a> DoubleEndedIterator for IterMut<'a> { @@ -511,6 +529,34 @@ impl<'a> ExactSizeIterator for Columns<'a> { } } +pub struct IntoColumns { + iter: std::vec::IntoIter<(String, Value)>, +} + +impl Iterator for IntoColumns { + type Item = String; + + fn next(&mut self) -> Option { + self.iter.next().map(|(col, _)| col) + } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } +} + +impl DoubleEndedIterator for IntoColumns { + fn next_back(&mut self) -> Option { + self.iter.next_back().map(|(col, _)| col) + } +} + +impl ExactSizeIterator for IntoColumns { + fn len(&self) -> usize { + self.iter.len() + } +} + pub struct Values<'a> { iter: std::slice::Iter<'a, (String, Value)>, }