We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
OptionExt
is_none_or
rustc_data_structures
1 parent 7592c13 commit ddc72feCopy full SHA for ddc72fe
compiler/rustc_data_structures/src/lib.rs
@@ -94,8 +94,10 @@ pub mod work_queue;
94
95
mod atomic_ref;
96
mod hashes;
97
+mod option_ext;
98
99
pub use atomic_ref::AtomicRef;
100
+pub use option_ext::OptionExt;
101
102
#[inline(never)]
103
#[cold]
compiler/rustc_data_structures/src/option_ext.rs
@@ -0,0 +1,18 @@
1
+/// Extension for [`Option`] that adds handy methods missing from it.
2
+pub trait OptionExt {
3
+ type T;
4
+
5
+ fn is_none_or(self, f: impl FnOnce(Self::T) -> bool) -> bool;
6
+}
7
8
+impl<T> OptionExt for Option<T> {
9
+ type T = T;
10
11
+ /// Returns `true` is `self` is `None` or the value inside matches a predicate `f`.
12
+ fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
13
+ match self {
14
+ None => true,
15
+ Some(x) => f(x),
16
+ }
17
18
0 commit comments