File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,20 @@ impl<T> Option<T> {
200
200
match self { None => def, Some ( v) => f ( v) }
201
201
}
202
202
203
+ /// As `map_consume`, but swaps a None into the original option rather
204
+ /// than consuming it by-value.
205
+ #[ inline]
206
+ pub fn take_map < U > ( & mut self , blk : & fn ( T ) -> U ) -> Option < U > {
207
+ util:: replace ( self , None ) . map_consume ( blk)
208
+ }
209
+
210
+ /// As `map_consume_default`, but swaps a None into the original option
211
+ /// rather than consuming it by-value.
212
+ #[ inline]
213
+ pub fn take_map_default < U > ( & mut self , def : U , blk : & fn ( T ) -> U ) -> U {
214
+ util:: replace ( self , None ) . map_consume_default ( def, blk)
215
+ }
216
+
203
217
/// Apply a function to the contained value or do nothing
204
218
pub fn mutate ( & mut self , f : & fn ( T ) -> T ) {
205
219
if self . is_some ( ) {
You can’t perform that action at this time.
0 commit comments