rust/library/core/tests/iter
Michal Nazarewicz 994e712162
Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith>
Repeat iterator always returns the same element and behaves the same way
backwards and forwards.  Take iterator can trivially implement backwards
iteration over Repeat inner iterator by simply doing forwards iteration.

DoubleEndedIterator is not currently implemented for Take<Repeat<T>>
because Repeat doesn’t implement ExactSizeIterator which is a required
bound on DEI implementation for Take.

Similarly, since Repeat is an infinite iterator which never stops, Take
can trivially know how many elements it’s going to return.  This allows
implementing ExactSizeIterator on Take<Repeat<T>>.

While at it, observe that ExactSizeIterator can also be implemented for
Take<RepeatWhile<F>> so add that implementation too.  Since in contrast
to Repeat, RepeatWhile doesn’t guarante to always return the same value,
DoubleEndedIterator isn’t implemented.

Those changes render core::iter::repeat_n somewhat redundant.

Issue: https://github.com/rust-lang/rust/issues/104434
Issue: https://github.com/rust-lang/rust/issues/104729
2023-01-16 17:56:01 +01:00
..
adapters Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> 2023-01-16 17:56:01 +01:00
traits Replace `NonZero::<_>::new` with `NonZero::new`. 2024-02-15 08:09:42 +01:00
mod.rs remove redundant imports 2023-12-10 10:56:22 +08:00
range.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00
sources.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00