mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 00:24:52 +00:00
doc: improve map_or and map_or_else
This commit is contained in:
parent
78c4d53871
commit
eb3566f239
|
@ -422,7 +422,8 @@ pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies a function to the contained value or returns a default.
|
||||
/// Applies a function to the contained value (if any),
|
||||
/// or returns a `default` (if not).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -435,14 +436,15 @@ pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn map_or<U, F: FnOnce(T) -> U>(self, def: U, f: F) -> U {
|
||||
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
|
||||
match self {
|
||||
Some(t) => f(t),
|
||||
None => def
|
||||
None => default,
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies a function to the contained value or computes a default.
|
||||
/// Applies a function to the contained value (if any),
|
||||
/// or computes a `default` (if not).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -457,10 +459,10 @@ pub fn map_or<U, F: FnOnce(T) -> U>(self, def: U, f: F) -> U {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(self, def: D, f: F) -> U {
|
||||
pub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(self, default: D, f: F) -> U {
|
||||
match self {
|
||||
Some(t) => f(t),
|
||||
None => def()
|
||||
None => default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue