Rollup merge of #107632 - ameknite:issue-107622-fix, r=jyn514

Clarifying that .map() returns None if None.

Fix #107622
This commit is contained in:
Michael Goulet 2023-02-03 14:15:24 -08:00 committed by GitHub
commit 13bd75f425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -943,7 +943,7 @@ pub const fn unwrap_or_default(self) -> 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 returns `None` (if `None`).
///
/// # Examples
///
@ -955,8 +955,10 @@ pub const fn unwrap_or_default(self) -> 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")]