Skip to content

Commit

Permalink
Auto merge of #56534 - xfix:copied, r=@SimonSapin
Browse files Browse the repository at this point in the history
Add unstable Iterator::copied()

Initially suggested at rust-itertools/itertools#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.
  • Loading branch information
bors committed Dec 26, 2018
2 parents 008c6a0 + 6fdc712 commit 1324c4d
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 1324c4d

Please sign in to comment.