diff options
| author | Ame <104745335+ameknite@users.noreply.github.com> | 2023-02-03 04:54:27 -0600 |
|---|---|---|
| committer | Ame <104745335+ameknite@users.noreply.github.com> | 2023-02-03 13:57:53 -0600 |
| commit | c2b65ffe295bf98cb1140ddb5f82efdb0f6f33ce (patch) | |
| tree | 21a8a04c2817001a38ee4fd2b2c8817006e928db | |
| parent | 9545094994f1ab45cab5799d5b45980871a9e97b (diff) | |
| download | rust-c2b65ffe295bf98cb1140ddb5f82efdb0f6f33ce.tar.gz rust-c2b65ffe295bf98cb1140ddb5f82efdb0f6f33ce.zip | |
Clarifying that .map() returns None if None.
| -rw-r--r-- | library/core/src/option.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index c43b728022d..f485763b234 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -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")] |
