Skip to content

Commit

Permalink
Auto merge of #47562 - Centril:feature/core_convert_id, r=oli-obk
Browse files Browse the repository at this point in the history
Add the identity function as core::convert::identity

## New notes

This implements rust-lang/rfcs#2306 (see rust-lang/rust#53500).

## Old notes (ignore this in new reviews)

Adds the identity function `fn id<T>(x: T) -> T { x }` to core::convert and the prelude.
Some motivations for why this is useful are explained in the doc tests.
Another is that using the identity function instead of `{ x }` or `|x| x` makes it clear that you intended to use an identity conversion on purpose.

The reasoning:
+ behind adding this to `convert` and not `mem` is that this is an identity *conversion*.
+ for adding this to the prelude is that it should be easy enough to use that the ease of writing your own identity function or using a closure `|x| x` doesn't overtake that.

I've separated this out into two feature gates so that the addition to the prelude can be considered and stabilized separately.

cc @bluss
  • Loading branch information
bors committed Aug 20, 2018
2 parents 36222fc + 2af42a8 commit ea41dbc
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit ea41dbc

Please sign in to comment.