about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2024-02-08 16:41:48 -0600
committerCameron Steffen <cam.steffen94@gmail.com>2024-02-09 09:53:30 -0600
commite9059cb8aaad3515e174ffa72783e36e34b95dd1 (patch)
treebde80aeac406305a2c7a3bdd8fdb18b8b42a84e4
parent8fb67fb37fed736cb04f307473af7c863be224fb (diff)
downloadrust-e9059cb8aaad3515e174ffa72783e36e34b95dd1.tar.gz
rust-e9059cb8aaad3515e174ffa72783e36e34b95dd1.zip
Improve Option::inspect docs
-rw-r--r--library/core/src/option.rs15
-rw-r--r--library/core/src/result.rs8
2 files changed, 16 insertions, 7 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index ab005228984..e37e62e32c4 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -1073,18 +1073,23 @@ impl<T> Option<T> {
         }
     }
 
-    /// Calls the provided closure with a reference to the contained value (if [`Some`]).
+    /// Calls a function with a reference to the contained value if [`Some`].
+    ///
+    /// Returns the original option.
     ///
     /// # Examples
     ///
     /// ```
-    /// let v = vec![1, 2, 3, 4, 5];
+    /// let list = vec![1, 2, 3];
     ///
-    /// // prints "got: 4"
-    /// let x: Option<&usize> = v.get(3).inspect(|x| println!("got: {x}"));
+    /// // prints "got: 2"
+    /// let x = list
+    ///     .get(1)
+    ///     .inspect(|x| println!("got: {x}"))
+    ///     .expect("list should be long enough");
     ///
     /// // prints nothing
-    /// let x: Option<&usize> = v.get(5).inspect(|x| println!("got: {x}"));
+    /// list.get(5).inspect(|x| println!("got: {x}"));
     /// ```
     #[inline]
     #[stable(feature = "result_option_inspect", since = "1.76.0")]
diff --git a/library/core/src/result.rs b/library/core/src/result.rs
index 1f448984e53..80f7fe75e82 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -830,7 +830,9 @@ impl<T, E> Result<T, E> {
         }
     }
 
-    /// Calls the provided closure with a reference to the contained value (if [`Ok`]).
+    /// Calls a function with a reference to the contained value if [`Ok`].
+    ///
+    /// Returns the original result.
     ///
     /// # Examples
     ///
@@ -851,7 +853,9 @@ impl<T, E> Result<T, E> {
         self
     }
 
-    /// Calls the provided closure with a reference to the contained error (if [`Err`]).
+    /// Calls a function with a reference to the contained value if [`Err`].
+    ///
+    /// Returns the original result.
     ///
     /// # Examples
     ///