File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,13 @@ impl<T> Option<T> {
264
264
#[ inline( always) ]
265
265
pure fn map < U > ( & self , f : fn ( x : & T ) -> U ) -> Option < U > { map ( self , f) }
266
266
267
+ /// As `map`, but consumes the option and gives `f` ownership to avoid
268
+ /// copying.
269
+ #[ inline( always) ]
270
+ pure fn map_consume < U > ( self , f : fn ( v : T ) -> U ) -> Option < U > {
271
+ map_consume ( self , f)
272
+ }
273
+
267
274
/// Applies a function to the contained value or returns a default
268
275
#[ inline( always) ]
269
276
pure fn map_default < U > ( & self , def : U , f : fn ( x : & T ) -> U ) -> U {
@@ -301,6 +308,17 @@ impl<T> Option<T> {
301
308
#[ inline( always) ]
302
309
pure fn unwrap ( self ) -> T { unwrap ( self ) }
303
310
311
+ /**
312
+ * The option dance. Moves a value out of an option type and returns it,
313
+ * replacing the original with `None`.
314
+ *
315
+ * # Failure
316
+ *
317
+ * Fails if the value equals `None`.
318
+ */
319
+ #[ inline( always) ]
320
+ fn swap_unwrap ( & mut self ) -> T { swap_unwrap ( self ) }
321
+
304
322
/**
305
323
* Gets the value out of an option, printing a specified message on
306
324
* failure
You can’t perform that action at this time.
0 commit comments