mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Add Record::into_columns
(#12324)
# Description Add `Record::into_columns` to complement `Record::columns` and `Record::into_values`.
This commit is contained in:
parent
af72a18785
commit
67e7eec7da
1 changed files with 46 additions and 0 deletions
|
@ -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::Item> {
|
||||
self.iter.next()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
impl DoubleEndedIterator for IntoIter {
|
||||
|
@ -421,6 +431,10 @@ impl<'a> Iterator for Iter<'a> {
|
|||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().map(|(col, val): &(_, _)| (col, val))
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
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::Item> {
|
||||
self.iter.next().map(|(col, val)| (&*col, val))
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
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::Item> {
|
||||
self.iter.next().map(|(col, _)| col)
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
impl DoubleEndedIterator for IntoColumns {
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
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)>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue