Add Record::into_columns (#12324)

# Description
Add `Record::into_columns` to complement `Record::columns` and
`Record::into_values`.
This commit is contained in:
Ian Manske 2024-04-14 20:43:47 +00:00 committed by GitHub
parent af72a18785
commit 67e7eec7da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -216,6 +216,12 @@ impl Record {
} }
} }
pub fn into_columns(self) -> IntoColumns {
IntoColumns {
iter: self.inner.into_iter(),
}
}
pub fn values(&self) -> Values { pub fn values(&self) -> Values {
Values { Values {
iter: self.inner.iter(), iter: self.inner.iter(),
@ -385,6 +391,10 @@ impl Iterator for IntoIter {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.iter.next() self.iter.next()
} }
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
} }
impl DoubleEndedIterator for IntoIter { impl DoubleEndedIterator for IntoIter {
@ -421,6 +431,10 @@ impl<'a> Iterator for Iter<'a> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(col, val): &(_, _)| (col, val)) 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> { impl<'a> DoubleEndedIterator for Iter<'a> {
@ -457,6 +471,10 @@ impl<'a> Iterator for IterMut<'a> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(col, val)| (&*col, val)) 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> { 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> { pub struct Values<'a> {
iter: std::slice::Iter<'a, (String, Value)>, iter: std::slice::Iter<'a, (String, Value)>,
} }