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 examples using .as_ref() for is_err_and and is_ok_and
  • Loading branch information
Natural-selection1 committed Apr 24, 2025
commit 56d5efc68c66c144d41a792a6f55db74a737ad56
8 changes: 8 additions & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ impl<T, E> Result<T, E> {
///
/// let x: Result<u32, &str> = Err("hey");
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
///
/// let x: Result<String, &str> = Ok("ownership".to_string());
/// assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true);
/// println!("still alive {:?}", x);
/// ```
#[must_use]
#[inline]
Expand Down Expand Up @@ -643,6 +647,10 @@ impl<T, E> Result<T, E> {
///
/// let x: Result<u32, Error> = Ok(123);
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
///
/// let x: Result<u32, &str> = Err("ownership");
/// assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true);
/// println!("still alive {:?}", x);
/// ```
#[must_use]
#[inline]
Expand Down
Loading