42
42
43
43
use crate :: fmt;
44
44
45
- /// An identity function.
45
+ /// The identity function.
46
46
///
47
47
/// Two things are important to note about this function:
48
48
///
49
- /// - It is not always equivalent to a closure like `|x| x` since the
49
+ /// - It is not always equivalent to a closure like `|x| x`, since the
50
50
/// closure may coerce `x` into a different type.
51
51
///
52
52
/// - It moves the input `x` passed to the function.
@@ -56,31 +56,32 @@ use crate::fmt;
56
56
///
57
57
/// # Examples
58
58
///
59
- /// Using `identity` to do nothing among other interesting functions:
59
+ /// Using `identity` to do nothing in a sequence of other, interesting,
60
+ /// functions:
60
61
///
61
62
/// ```rust
62
63
/// use std::convert::identity;
63
64
///
64
65
/// fn manipulation(x: u32) -> u32 {
65
- /// // Let's assume that this function does something interesting.
66
+ /// // Let's pretend that adding one is an interesting function .
66
67
/// x + 1
67
68
/// }
68
69
///
69
70
/// let _arr = &[identity, manipulation];
70
71
/// ```
71
72
///
72
- /// Using `identity` to get a function that changes nothing in a conditional:
73
+ /// Using `identity` as a "do nothing" base case in a conditional:
73
74
///
74
75
/// ```rust
75
76
/// use std::convert::identity;
76
77
///
77
78
/// # let condition = true;
78
- ///
79
+ /// #
79
80
/// # fn manipulation(x: u32) -> u32 { x + 1 }
80
- ///
81
+ /// #
81
82
/// let do_stuff = if condition { manipulation } else { identity };
82
83
///
83
- /// // do more interesting stuff..
84
+ /// // Do more interesting stuff. ..
84
85
///
85
86
/// let _results = do_stuff(42);
86
87
/// ```
0 commit comments