Impl FusedIterator for record iterators (#12542)

This is good practice as all our iterators will never return a value
after reaching `None`

The benefit should be minimal as only `Iterator::fuse` is directly
specialized and itself rarely used (sometimes in `itertools` adaptors)

Thus it is mostly a documentation thing
This commit is contained in:
Stefan Holderbach 2024-04-17 00:34:16 +02:00 committed by GitHub
parent a67dad3d15
commit 055aae9f5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
use std::ops::RangeBounds; use std::{iter::FusedIterator, ops::RangeBounds};
use crate::{ShellError, Span, Value}; use crate::{ShellError, Span, Value};
@ -409,6 +409,8 @@ impl ExactSizeIterator for IntoIter {
} }
} }
impl FusedIterator for IntoIter {}
impl IntoIterator for Record { impl IntoIterator for Record {
type Item = (String, Value); type Item = (String, Value);
@ -449,6 +451,8 @@ impl<'a> ExactSizeIterator for Iter<'a> {
} }
} }
impl FusedIterator for Iter<'_> {}
impl<'a> IntoIterator for &'a Record { impl<'a> IntoIterator for &'a Record {
type Item = (&'a String, &'a Value); type Item = (&'a String, &'a Value);
@ -489,6 +493,8 @@ impl<'a> ExactSizeIterator for IterMut<'a> {
} }
} }
impl FusedIterator for IterMut<'_> {}
impl<'a> IntoIterator for &'a mut Record { impl<'a> IntoIterator for &'a mut Record {
type Item = (&'a String, &'a mut Value); type Item = (&'a String, &'a mut Value);
@ -529,6 +535,8 @@ impl<'a> ExactSizeIterator for Columns<'a> {
} }
} }
impl FusedIterator for Columns<'_> {}
pub struct IntoColumns { pub struct IntoColumns {
iter: std::vec::IntoIter<(String, Value)>, iter: std::vec::IntoIter<(String, Value)>,
} }
@ -557,6 +565,8 @@ impl ExactSizeIterator for IntoColumns {
} }
} }
impl FusedIterator for IntoColumns {}
pub struct Values<'a> { pub struct Values<'a> {
iter: std::slice::Iter<'a, (String, Value)>, iter: std::slice::Iter<'a, (String, Value)>,
} }
@ -585,6 +595,8 @@ impl<'a> ExactSizeIterator for Values<'a> {
} }
} }
impl FusedIterator for Values<'_> {}
pub struct IntoValues { pub struct IntoValues {
iter: std::vec::IntoIter<(String, Value)>, iter: std::vec::IntoIter<(String, Value)>,
} }
@ -613,6 +625,8 @@ impl ExactSizeIterator for IntoValues {
} }
} }
impl FusedIterator for IntoValues {}
pub struct Drain<'a> { pub struct Drain<'a> {
iter: std::vec::Drain<'a, (String, Value)>, iter: std::vec::Drain<'a, (String, Value)>,
} }
@ -641,6 +655,8 @@ impl ExactSizeIterator for Drain<'_> {
} }
} }
impl FusedIterator for Drain<'_> {}
#[macro_export] #[macro_export]
macro_rules! record { macro_rules! record {
// The macro only compiles if the number of columns equals the number of values, // The macro only compiles if the number of columns equals the number of values,