| Age | Commit message (Collapse) | Author | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Add unstable Iterator::copied()
Initially suggested at https://github.com/bluss/rust-itertools/pull/289, however the maintainers of itertools suggested this may be better of in a standard library.
The intent of `copied` is to avoid accidentally cloning iterator elements after doing a code refactoring which causes a structure to be no longer `Copy`. This is a relatively common pattern, as it can be seen by calling `rg --pcre2 '[.]map[(][|](?:(\w+)[|] [*]\1|&(\w+)[|] \2)[)]'` on Rust main repository. Additionally, many uses of `cloned` actually want to simply `Copy`, and changing something to be no longer copyable may introduce unnoticeable performance penalty.
Also, this makes sense because the standard library includes `[T].copy_from_slice` to pair with `[T].clone_from_slice`.
This also adds `Option::copied`, because it makes sense to pair it with `Iterator::copied`. I don't think this feature is particularly important, but it makes sense to update `Option` along with `Iterator` for consistency.
|
|
|
|
|
|
Add missing link in docs
r? @steveklabnik
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
to #49098
|
|
|
|
- reword messages
- apply custom comments to all types of ranges
- fix indentation
|
|
|
|
- Detect one element array of `Range` type, which is potentially a typo:
`for _ in [0..10] {}` where iterating between `0` and `10` was intended.
(#23141)
- Suggest `.bytes()` and `.chars()` for `String`.
- Suggest borrowing or `.iter()` on arrays (#36391)
- Suggest using range literal when iterating on integers (#34353)
- Do not suggest `.iter()` by default (#50773, #46806)
|
|
|
|
Stablize Iterator::find_map
Stabilization PR for https://github.com/rust-lang/rust/issues/49602
|
|
|
|
|
|
|
|
|
|
Fixes https://github.com/rust-lang/rust/issues/52279.
|
|
this gives us some leeway when optimizing
|
|
r=SimonSapin
Stabilize Iterator::flatten in 1.29, fixes #48213.
This PR stabilizes [`Iterator::flatten`](https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.flatten) in *version 1.29* (1.28 goes to beta in 10 days, I don't think there's enough time to land it in that time, but let's see...).
Tracking issue is: #48213.
cc @bluss re. itertools.
r? @SimonSapin
ping @pietroalbini -- let's do a crater run when this passes CI :)
|
|
|
|
|
|
Fixes #27741
|
|
|
|
Fixes https://github.com/rust-lang/rust/issues/50225.
|
|
|
|
|
|
Stabilize iterator methods in 1.27
- Closes #39480, feature `iter_rfind`
- `DoubleEndedIterator::rfind`
- Closes #44705, feature `iter_rfold`
- `DoubleEndedIterator::rfold`
- Closes #45594, feature `iterator_try_fold`
- `Iterator::try_fold`
- `Iterator::try_for_each`
- `DoubleEndedIterator::try_rfold`
|
|
Add #[must_use] to a few standard library methods
Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged.
Discuss :)
```rust
warning: unused return value of `std::iter::Iterator::collect` which must be used: if you really need to exhaust the iterator, consider `.for_each(drop)` instead
--> $DIR/fn_must_use_stdlib.rs:19:5
|
LL | "1 2 3".split_whitespace().collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused return value of `std::borrow::ToOwned::to_owned` which must be used: cloning is often expensive and is not expected to have side effects
--> $DIR/fn_must_use_stdlib.rs:21:5
|
LL | "hello".to_owned();
| ^^^^^^^^^^^^^^^^^^^
warning: unused return value of `std::clone::Clone::clone` which must be used: cloning is often expensive and is not expected to have side effects
--> $DIR/fn_must_use_stdlib.rs:23:5
|
LL | String::from("world").clone();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
cc https://github.com/rust-lang/rust/issues/48926
|
|
|
|
|
|
Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged.
Discuss :)
|
|
The comment "the value passed on to the next iteration" confused me since it sounded more like what Haskell's [scanl](http://hackage.haskell.org/package/base-4.11.0.0/docs/Prelude.html#v:scanl) does where the closure's return value serves as both the "yielded value" *and* the new value of the "state".
I tried changing the example to make it clear that the closure's return value is decoupled from the state argument.
|
|
doc: no need for the reference
Also, we are well within line length limit
|
|
Also:
- apply some rustfmt love
- fix output of one example
|