Skip to content

Commit d0ac97d

Browse files
add examples using .as_ref() for is_some_and and is_none_or
1 parent c0446d3 commit d0ac97d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/option.rs

+8
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@ impl<T> Option<T> {
638638
///
639639
/// let x: Option<u32> = None;
640640
/// assert_eq!(x.is_some_and(|x| x > 1), false);
641+
///
642+
/// let x: Option<String> = Some("ownership".to_string());
643+
/// assert_eq!(x.as_ref().is_some_and(|x| x.len() > 1), true);
644+
/// println!("still alive {:?}", x);
641645
/// ```
642646
#[must_use]
643647
#[inline]
@@ -682,6 +686,10 @@ impl<T> Option<T> {
682686
///
683687
/// let x: Option<u32> = None;
684688
/// assert_eq!(x.is_none_or(|x| x > 1), true);
689+
///
690+
/// let x: Option<String> = Some("ownership".to_string());
691+
/// assert_eq!(x.as_ref().is_none_or(|x| x.len() > 1), true);
692+
/// println!("still alive {:?}", x);
685693
/// ```
686694
#[must_use]
687695
#[inline]

0 commit comments

Comments
 (0)