From 055aae9f5cbbb13ebbc6ebdfef2f3658aebf6047 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Wed, 17 Apr 2024 00:34:16 +0200 Subject: [PATCH] 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 --- crates/nu-protocol/src/value/record.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/nu-protocol/src/value/record.rs b/crates/nu-protocol/src/value/record.rs index 6aedbc5755..8b61e61f7f 100644 --- a/crates/nu-protocol/src/value/record.rs +++ b/crates/nu-protocol/src/value/record.rs @@ -1,4 +1,4 @@ -use std::ops::RangeBounds; +use std::{iter::FusedIterator, ops::RangeBounds}; use crate::{ShellError, Span, Value}; @@ -409,6 +409,8 @@ impl ExactSizeIterator for IntoIter { } } +impl FusedIterator for IntoIter {} + impl IntoIterator for Record { type Item = (String, Value); @@ -449,6 +451,8 @@ impl<'a> ExactSizeIterator for Iter<'a> { } } +impl FusedIterator for Iter<'_> {} + impl<'a> IntoIterator for &'a Record { 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 { type Item = (&'a String, &'a mut Value); @@ -529,6 +535,8 @@ impl<'a> ExactSizeIterator for Columns<'a> { } } +impl FusedIterator for Columns<'_> {} + pub struct IntoColumns { iter: std::vec::IntoIter<(String, Value)>, } @@ -557,6 +565,8 @@ impl ExactSizeIterator for IntoColumns { } } +impl FusedIterator for IntoColumns {} + pub struct Values<'a> { iter: std::slice::Iter<'a, (String, Value)>, } @@ -585,6 +595,8 @@ impl<'a> ExactSizeIterator for Values<'a> { } } +impl FusedIterator for Values<'_> {} + pub struct IntoValues { iter: std::vec::IntoIter<(String, Value)>, } @@ -613,6 +625,8 @@ impl ExactSizeIterator for IntoValues { } } +impl FusedIterator for IntoValues {} + pub struct Drain<'a> { iter: std::vec::Drain<'a, (String, Value)>, } @@ -641,6 +655,8 @@ impl ExactSizeIterator for Drain<'_> { } } +impl FusedIterator for Drain<'_> {} + #[macro_export] macro_rules! record { // The macro only compiles if the number of columns equals the number of values,