Skip to content

Commit

Permalink
Rollup merge of #107632 - ameknite:issue-107622-fix, r=jyn514
Browse files Browse the repository at this point in the history
Clarifying that .map() returns None if None.

Fix #107622
  • Loading branch information
compiler-errors authored Feb 3, 2023
2 parents ef520bd + b384692 commit 13bd75f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 returns `None` (if `None`).
///
/// # Examples
///
Expand All @@ -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")]
Expand Down

0 comments on commit 13bd75f

Please sign in to comment.