diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index 23a41f0cb..c3edc6487 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -728,6 +728,11 @@ impl Iterator for TupleCombinations } } +impl FusedIterator for TupleCombinations + where I: FusedIterator, + T: HasCombination, +{} + #[derive(Clone, Debug)] pub struct Tuple1Combination { iter: I, diff --git a/src/combinations_with_replacement.rs b/src/combinations_with_replacement.rs index 1f1bcf5b2..81b13f130 100644 --- a/src/combinations_with_replacement.rs +++ b/src/combinations_with_replacement.rs @@ -1,5 +1,6 @@ use alloc::vec::Vec; use std::fmt; +use std::iter::FusedIterator; use super::lazy_buffer::LazyBuffer; @@ -100,3 +101,9 @@ where } } } + +impl FusedIterator for CombinationsWithReplacement +where + I: Iterator, + I::Item: Clone, +{} diff --git a/src/kmerge_impl.rs b/src/kmerge_impl.rs index 36bfc5a8a..dce5b782c 100644 --- a/src/kmerge_impl.rs +++ b/src/kmerge_impl.rs @@ -2,6 +2,7 @@ use crate::size_hint; use crate::Itertools; use alloc::vec::Vec; +use std::iter::FusedIterator; use std::mem::replace; use std::fmt; @@ -219,3 +220,8 @@ impl Iterator for KMergeBy .unwrap_or((0, Some(0))) } } + +impl FusedIterator for KMergeBy + where I: Iterator, + F: KMergePredicate +{} diff --git a/src/pad_tail.rs b/src/pad_tail.rs index 18e666bad..03867cbf0 100644 --- a/src/pad_tail.rs +++ b/src/pad_tail.rs @@ -1,4 +1,4 @@ -use std::iter::Fuse; +use std::iter::{Fuse, FusedIterator}; use crate::size_hint; /// An iterator adaptor that pads a sequence to a minimum length by filling @@ -81,3 +81,9 @@ impl ExactSizeIterator for PadUsing where I: ExactSizeIterator, F: FnMut(usize) -> I::Item {} + + +impl FusedIterator for PadUsing + where I: FusedIterator, + F: FnMut(usize) -> I::Item +{} diff --git a/src/powerset.rs b/src/powerset.rs index ef17752b3..f50d860a2 100644 --- a/src/powerset.rs +++ b/src/powerset.rs @@ -1,4 +1,5 @@ use std::fmt; +use std::iter::FusedIterator; use std::usize; use alloc::vec::Vec; @@ -81,3 +82,9 @@ impl Iterator for Powerset } } } + +impl FusedIterator for Powerset + where + I: Iterator, + I::Item: Clone, +{} diff --git a/src/rciter_impl.rs b/src/rciter_impl.rs index 9122dadc9..782908e28 100644 --- a/src/rciter_impl.rs +++ b/src/rciter_impl.rs @@ -1,5 +1,5 @@ -use std::iter::IntoIterator; +use std::iter::{FusedIterator, IntoIterator}; use alloc::rc::Rc; use std::cell::RefCell; @@ -93,3 +93,8 @@ impl<'a, I> IntoIterator for &'a RcIter self.clone() } } + + +impl FusedIterator for RcIter + where I: FusedIterator +{} diff --git a/src/repeatn.rs b/src/repeatn.rs index 8bc485083..94a02651b 100644 --- a/src/repeatn.rs +++ b/src/repeatn.rs @@ -1,3 +1,4 @@ +use std::iter::FusedIterator; /// An iterator that produces *n* repetitions of an element. /// @@ -52,3 +53,7 @@ impl DoubleEndedIterator for RepeatN impl ExactSizeIterator for RepeatN where A: Clone {} + +impl FusedIterator for RepeatN + where A: Clone +{} diff --git a/src/tuple_impl.rs b/src/tuple_impl.rs index 82ecd8632..ca8b97c6a 100644 --- a/src/tuple_impl.rs +++ b/src/tuple_impl.rs @@ -1,6 +1,7 @@ //! Some iterator that produces tuples use std::iter::Fuse; +use std::iter::FusedIterator; use std::iter::Take; use std::iter::Cycle; use std::marker::PhantomData; @@ -187,6 +188,12 @@ impl Iterator for TupleWindows } } +impl FusedIterator for TupleWindows + where I: FusedIterator, + T: HomogeneousTuple + Clone, + T::Item: Clone +{} + /// An iterator over all windows,wrapping back to the first elements when the /// window would otherwise exceed the length of the iterator, producing tuples /// of a specific size. diff --git a/src/with_position.rs b/src/with_position.rs index c53b652c6..1388503d1 100644 --- a/src/with_position.rs +++ b/src/with_position.rs @@ -1,4 +1,4 @@ -use std::iter::{Fuse,Peekable}; +use std::iter::{Fuse,Peekable, FusedIterator}; /// An iterator adaptor that wraps each element in an [`Position`]. /// @@ -95,3 +95,6 @@ impl Iterator for WithPosition { impl ExactSizeIterator for WithPosition where I: ExactSizeIterator, { } + +impl FusedIterator for WithPosition +{} diff --git a/tests/quick.rs b/tests/quick.rs index 0ea51ece1..7e222a641 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1618,6 +1618,18 @@ quickcheck! { is_fused(a.combinations(3)) } + fn fused_combination_with_replacement(a: Iter) -> bool + { + is_fused(a.clone().combinations_with_replacement(1)) && + is_fused(a.combinations_with_replacement(3)) + } + + fn fused_tuple_combination(a: Iter) -> bool + { + is_fused(a.clone().fuse().tuple_combinations::<(_,)>()) && + is_fused(a.fuse().tuple_combinations::<(_,_,_)>()) + } + fn fused_unique(a: Iter) -> bool { is_fused(a.fuse().unique()) @@ -1669,5 +1681,15 @@ quickcheck! { !is_fused(a.clone().update(|x|*x+=1)) && is_fused(a.fuse().update(|x|*x+=1)) } + + fn fused_tuple_windows(a: Iter) -> bool + { + is_fused(a.fuse().tuple_windows::<(_,_)>()) + } + + fn fused_pad_using(a: Iter) -> bool + { + is_fused(a.fuse().pad_using(100,|_|0)) + } }