rust/library/core/tests/iter/adapters
Josh Stone 974bc455ee Specialize flattening iterators with only one inner item
For iterators like `Once` and `option::IntoIter` that only ever have a
single item at most, the front and back iterator states in `FlatMap` and
`Flatten` are a waste, as they're always consumed already. We can use
specialization for these types to simplify the iterator methods.

It's a somewhat common pattern to use `flatten()` for options and
results, even recommended by [multiple][1] [clippy][2] [lints][3]. The
implementation is more efficient with `filter_map`, as mentioned in
[clippy#9377], but this new specialization should close some of that
gap for existing code that flattens.

[1]: https://rust-lang.github.io/rust-clippy/master/#filter_map_identity
[2]: https://rust-lang.github.io/rust-clippy/master/#option_filter_map
[3]: https://rust-lang.github.io/rust-clippy/master/#result_filter_map
[clippy#9377]: https://github.com/rust-lang/rust-clippy/issues/9377
2024-02-16 13:49:29 -08:00
..
array_chunks.rs remove redundant imports 2023-12-10 10:56:22 +08:00
by_ref_sized.rs
chain.rs Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
cloned.rs
copied.rs
cycle.rs
enumerate.rs Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
filter_map.rs
filter.rs
flat_map.rs
flatten.rs Specialize flattening iterators with only one inner item 2024-02-16 13:49:29 -08:00
fuse.rs
inspect.rs
intersperse.rs
map_windows.rs Add Iterator::map_windows 2023-08-11 07:26:51 +08:00
map.rs
mod.rs Add Iterator::map_windows 2023-08-11 07:26:51 +08:00
peekable.rs
scan.rs
skip_while.rs
skip.rs Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
step_by.rs Auto merge of #85528 - the8472:iter-markers, r=dtolnay 2024-01-21 11:17:46 +00:00
take_while.rs
take.rs Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
zip.rs apply fmt 2024-01-11 15:04:48 +03:00