Skip to content

Commit 942eaa7

Browse files
committed
Add negative example for Result::and_then
1 parent bd421e2 commit 942eaa7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/core/src/result.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,14 @@ impl<T, E> Result<T, E> {
12931293
/// Often used to chain fallible operations that may return [`Err`].
12941294
///
12951295
/// ```
1296-
/// use std::path::Path;
1296+
/// use std::{io::ErrorKind, path::Path};
12971297
///
12981298
/// let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified());
1299-
/// assert!(root_modified_time.is_ok())
1299+
/// assert!(root_modified_time.is_ok());
1300+
///
1301+
/// let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified());
1302+
/// assert!(should_fail.is_err());
1303+
/// assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound);
13001304
/// ```
13011305
#[inline]
13021306
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)