File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
compiler/rustc_data_structures/src Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -94,8 +94,10 @@ pub mod work_queue;
94
94
95
95
mod atomic_ref;
96
96
mod hashes;
97
+ mod option_ext;
97
98
98
99
pub use atomic_ref:: AtomicRef ;
100
+ pub use option_ext:: OptionExt ;
99
101
100
102
#[ inline( never) ]
101
103
#[ cold]
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments