From c2b65ffe295bf98cb1140ddb5f82efdb0f6f33ce Mon Sep 17 00:00:00 2001 From: Ame <104745335+ameknite@users.noreply.github.com> Date: Fri, 3 Feb 2023 04:54:27 -0600 Subject: [PATCH 1/2] Clarifying that .map() returns None if None. --- library/core/src/option.rs | 6 ++++-- 1 file 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 Option { // Transforming contained values ///////////////////////////////////////////////////////////////////////// - /// Maps an `Option` to `Option` by applying a function to a contained value. + /// Maps an `Option` to `Option` by applying a function to a contained value (if `Some`) or return `None` (if `None`). /// /// # Examples /// @@ -955,8 +955,10 @@ impl Option { /// 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")] From b384692f4c7fa61b36f9314d6e597154914f4957 Mon Sep 17 00:00:00 2001 From: Ame <104745335+ameknite@users.noreply.github.com> Date: Fri, 3 Feb 2023 11:41:59 -0600 Subject: [PATCH 2/2] nit fixed --- library/core/src/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index f485763b234..5d5e9559034 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -943,7 +943,7 @@ impl Option { // Transforming contained values ///////////////////////////////////////////////////////////////////////// - /// Maps an `Option` to `Option` by applying a function to a contained value (if `Some`) or return `None` (if `None`). + /// Maps an `Option` to `Option` by applying a function to a contained value (if `Some`) or returns `None` (if `None`). /// /// # Examples ///