mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Clarifying that .map() returns None if None.
This commit is contained in:
parent
9545094994
commit
c2b65ffe29
@ -943,7 +943,7 @@ impl<T> Option<T> {
|
||||
// Transforming contained values
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
|
||||
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value (if `Some`) or return `None` (if `None`).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -955,8 +955,10 @@ impl<T> Option<T> {
|
||||
/// let maybe_some_string = Some(String::from("Hello, World!"));
|
||||
/// // `Option::map` takes self *by value*, consuming `maybe_some_string`
|
||||
/// let maybe_some_len = maybe_some_string.map(|s| s.len());
|
||||
///
|
||||
/// assert_eq!(maybe_some_len, Some(13));
|
||||
///
|
||||
/// let x: Option<&str> = None;
|
||||
/// assert_eq!(x.map(|s| s.len()), None);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user