Skip to content

Commit 13bd75f

Browse files
Rollup merge of #107632 - ameknite:issue-107622-fix, r=jyn514
Clarifying that .map() returns None if None. Fix #107622
2 parents ef520bd + b384692 commit 13bd75f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/core/src/option.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ impl<T> Option<T> {
943943
// Transforming contained values
944944
/////////////////////////////////////////////////////////////////////////
945945

946-
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
946+
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value (if `Some`) or returns `None` (if `None`).
947947
///
948948
/// # Examples
949949
///
@@ -955,8 +955,10 @@ impl<T> Option<T> {
955955
/// let maybe_some_string = Some(String::from("Hello, World!"));
956956
/// // `Option::map` takes self *by value*, consuming `maybe_some_string`
957957
/// let maybe_some_len = maybe_some_string.map(|s| s.len());
958-
///
959958
/// assert_eq!(maybe_some_len, Some(13));
959+
///
960+
/// let x: Option<&str> = None;
961+
/// assert_eq!(x.map(|s| s.len()), None);
960962
/// ```
961963
#[inline]
962964
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)