Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add negative example for Result::and_then
  • Loading branch information
cyqsimon committed Feb 11, 2022
commit 942eaa7ffcebad5592bf6865ef8c9e8959ec5b79
8 changes: 6 additions & 2 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down