Skip to content

Commit 45dee47

Browse files
committed
Improve is_err_with example.
1 parent 148234f commit 45dee47

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

library/core/src/result.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,16 @@ impl<T, E> Result<T, E> {
589589
/// # Examples
590590
///
591591
/// ```
592-
/// let x: Result<u32, &str> = Err("abc");
593-
/// assert_eq!(x.is_err_with(|x| x.len() > 1), true);
592+
/// use std::io::{Error, ErrorKind};
594593
///
595-
/// let x: Result<u32, &str> = Err("");
596-
/// assert_eq!(x.is_ok_with(|x| x.len() > 1), false);
594+
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
595+
/// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), true);
597596
///
598-
/// let x: Result<u32, &str> = Ok(123);
599-
/// assert_eq!(x.is_ok_with(|x| x.len() > 1), false);
597+
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::PermissionDenied, "!"));
598+
/// assert_eq!(x.is_ok_with(|x| x.kind() == ErrorKind::NotFound), false);
599+
///
600+
/// let x: Result<u32, Error> = Ok(123);
601+
/// assert_eq!(x.is_ok_with(|x| x.kind() == ErrorKind::NotFound), false);
600602
/// ```
601603
#[must_use]
602604
#[inline]

0 commit comments

Comments
 (0)