Content-Length: 309290 | pFad | https://github.com/model-checking/verify-rust-std/commit/b482e06e29c3e92fa9b817a33c53de672115f30e

83 add is_none_or · model-checking/verify-rust-std@b482e06 · GitHub
Skip to content

Commit b482e06

Browse files
committed
add is_none_or
1 parent 209f8c8 commit b482e06

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core/src/option.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,32 @@ impl<T> Option<T> {
654654
!self.is_some()
655655
}
656656

657+
//github.com/ Returns `true` if the option is a [`None`] or the value inside of it matches a predicate.
658+
//github.com/
659+
//github.com/ # Examples
660+
//github.com/
661+
//github.com/ ```
662+
//github.com/ #![feature(is_none_or)]
663+
//github.com/
664+
//github.com/ let x: Option<u32> = Some(2);
665+
//github.com/ assert_eq!(x.is_none_or(|x| x > 1), true);
666+
//github.com/
667+
//github.com/ let x: Option<u32> = Some(0);
668+
//github.com/ assert_eq!(x.is_none_or(|x| x > 1), false);
669+
//github.com/
670+
//github.com/ let x: Option<u32> = None;
671+
//github.com/ assert_eq!(x.is_none_or(|x| x > 1), true);
672+
//github.com/ ```
673+
#[must_use]
674+
#[inline]
675+
#[unstable(feature = "is_none_or", issue = "none")]
676+
pub fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
677+
match self {
678+
None => true,
679+
Some(x) => f(x),
680+
}
681+
}
682+
657683
//github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com//
658684
// Adapter for working with references
659685
//github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com//

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/model-checking/verify-rust-std/commit/b482e06e29c3e92fa9b817a33c53de672115f30e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy