Skip to content

Commit 56d5efc

Browse files
add examples using .as_ref() for is_err_and and is_ok_and
1 parent f86cd70 commit 56d5efc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/result.rs

+8
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ impl<T, E> Result<T, E> {
598598
///
599599
/// let x: Result<u32, &str> = Err("hey");
600600
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
601+
///
602+
/// let x: Result<String, &str> = Ok("ownership".to_string());
603+
/// assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true);
604+
/// println!("still alive {:?}", x);
601605
/// ```
602606
#[must_use]
603607
#[inline]
@@ -643,6 +647,10 @@ impl<T, E> Result<T, E> {
643647
///
644648
/// let x: Result<u32, Error> = Ok(123);
645649
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
650+
///
651+
/// let x: Result<u32, &str> = Err("ownership");
652+
/// assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true);
653+
/// println!("still alive {:?}", x);
646654
/// ```
647655
#[must_use]
648656
#[inline]

0 commit comments

Comments
 (0)