about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcyqsimon <28627918+cyqsimon@users.noreply.github.com>2022-02-11 09:55:47 +0800
committercyqsimon <28627918+cyqsimon@users.noreply.github.com>2022-02-11 09:57:19 +0800
commit942eaa7ffcebad5592bf6865ef8c9e8959ec5b79 (patch)
tree23852283ca7092b076126a65d319a2045acf67ed
parentbd421e2880d3c67ce77c3286d933be8171d0aaa9 (diff)
downloadrust-942eaa7ffcebad5592bf6865ef8c9e8959ec5b79.tar.gz
rust-942eaa7ffcebad5592bf6865ef8c9e8959ec5b79.zip
Add negative example for `Result::and_then`
-rw-r--r--library/core/src/result.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/core/src/result.rs b/library/core/src/result.rs
index bd7333a33e1..58d58ff0f72 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -1293,10 +1293,14 @@ impl<T, E> Result<T, E> {
     /// Often used to chain fallible operations that may return [`Err`].
     ///
     /// ```
-    /// use std::path::Path;
+    /// use std::{io::ErrorKind, path::Path};
     ///
     /// let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified());
-    /// assert!(root_modified_time.is_ok())
+    /// assert!(root_modified_time.is_ok());
+    ///
+    /// let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified());
+    /// assert!(should_fail.is_err());
+    /// assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound);
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]