Skip to content

Commit

Permalink
Rollup merge of rust-lang#64509 - varkor:convert-identity-doc-fixes, …
Browse files Browse the repository at this point in the history
…r=Centril

Make some adjustments to the documentation for `std::convert::identity`

Fixes some extra blank lines and makes some minor tweaks to the wording.
  • Loading branch information
Centril authored Sep 16, 2019
2 parents a31d71f + 18b24b7 commit a5a7ed6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@

use crate::fmt;

/// An identity function.
/// The identity function.
///
/// Two things are important to note about this function:
///
/// - It is not always equivalent to a closure like `|x| x` since the
/// - It is not always equivalent to a closure like `|x| x`, since the
/// closure may coerce `x` into a different type.
///
/// - It moves the input `x` passed to the function.
Expand All @@ -56,31 +56,32 @@ use crate::fmt;
///
/// # Examples
///
/// Using `identity` to do nothing among other interesting functions:
/// Using `identity` to do nothing in a sequence of other, interesting,
/// functions:
///
/// ```rust
/// use std::convert::identity;
///
/// fn manipulation(x: u32) -> u32 {
/// // Let's assume that this function does something interesting.
/// // Let's pretend that adding one is an interesting function.
/// x + 1
/// }
///
/// let _arr = &[identity, manipulation];
/// ```
///
/// Using `identity` to get a function that changes nothing in a conditional:
/// Using `identity` as a "do nothing" base case in a conditional:
///
/// ```rust
/// use std::convert::identity;
///
/// # let condition = true;
///
/// #
/// # fn manipulation(x: u32) -> u32 { x + 1 }
///
/// #
/// let do_stuff = if condition { manipulation } else { identity };
///
/// // do more interesting stuff..
/// // Do more interesting stuff...
///
/// let _results = do_stuff(42);
/// ```
Expand Down

0 comments on commit a5a7ed6

Please sign in to comment.