rust/library/core/tests/iter/adapters
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
..
array_chunks.rs remove redundant imports 2023-12-10 10:56:22 +08:00
by_ref_sized.rs Properly forward `ByRefSized::fold` to the inner iterator 2022-08-14 22:55:30 -07:00
chain.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00
cloned.rs library/core/test/iter add newlines between tests 2021-01-22 16:58:21 -05:00
copied.rs library/core/test/iter.rs split attempt 2 2021-01-21 19:36:32 -05:00
cycle.rs library/core/test/iter.rs split attempt 2 2021-01-21 19:36:32 -05:00
enumerate.rs Replace `NonZero::<_>::new` with `NonZero::new`. 2024-02-15 08:09:42 +01:00
filter.rs regression test for leaks in the the Filter::next_chunk implementation 2024-06-25 23:22:27 +02:00
filter_map.rs library/core/tests/iter rearrange & add back missed doc comments 2021-01-22 17:57:07 -05:00
flat_map.rs library/core/tests/iter rearrange & add back missed doc comments 2021-01-22 17:57:07 -05:00
flatten.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00
fuse.rs library/core/tests/iter rearrange & add back missed doc comments 2021-01-22 17:57:07 -05:00
inspect.rs library/core/test/iter add newlines between tests 2021-01-22 16:58:21 -05:00
intersperse.rs eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
map.rs library/core/tests/iter rearrange & add back missed doc comments 2021-01-22 17:57:07 -05:00
map_windows.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00
mod.rs Add Iterator::map_windows 2023-08-11 07:26:51 +08:00
peekable.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00
scan.rs library/core/test/iter.rs split attempt 2 2021-01-21 19:36:32 -05:00
skip.rs Replace `NonZero::<_>::new` with `NonZero::new`. 2024-02-15 08:09:42 +01:00
skip_while.rs library/core/test/iter add newlines between tests 2021-01-22 16:58:21 -05:00
step_by.rs step cfgs 2024-03-20 08:49:13 -04:00
take.rs Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> 2023-01-16 17:56:01 +01:00
take_while.rs library/core/test/iter add newlines between tests 2021-01-22 16:58:21 -05:00
zip.rs Reformat `use` declarations. 2024-07-29 08:26:52 +10:00