@@ -114,7 +114,7 @@ pub pure fn map_consume<T, U>(opt: Option<T>,
114
114
* As `map`, but consumes the option and gives `f` ownership to avoid
115
115
* copying.
116
116
*/
117
- match opt { None => None , Some ( v ) => Some ( f ( v ) ) }
117
+ if opt. is_some ( ) { Some ( f ( option :: unwrap ( move opt ) ) ) } else { None }
118
118
}
119
119
120
120
pub pure fn chain < T , U > ( opt : Option < T > ,
@@ -264,42 +264,12 @@ 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
-
274
267
/// Applies a function to the contained value or returns a default
275
268
#[ inline( always) ]
276
269
pure fn map_default < U > ( & self , def : U , f : fn ( x : & T ) -> U ) -> U {
277
270
map_default ( self , move def, f)
278
271
}
279
272
280
- /// As `map_default`, but consumes the option and gives `f`
281
- /// ownership to avoid copying.
282
- #[ inline( always) ]
283
- pure fn map_consume_default < U > ( self , def : U , f : fn ( v : T ) -> U ) -> U {
284
- match self { None => def, Some ( v) => f ( v) }
285
- }
286
-
287
- /// Apply a function to the contained value or do nothing
288
- fn mutate ( & mut self , f : fn ( T ) -> T ) {
289
- if self . is_some ( ) {
290
- * self = Some ( f ( self . swap_unwrap ( ) ) ) ;
291
- }
292
- }
293
-
294
- /// Apply a function to the contained value or set it to a default
295
- fn mutate_default ( & mut self , def : T , f : fn ( T ) -> T ) {
296
- if self . is_some ( ) {
297
- * self = Some ( f ( self . swap_unwrap ( ) ) ) ;
298
- } else {
299
- * self = Some ( def) ;
300
- }
301
- }
302
-
303
273
/// Performs an operation on the contained value by reference
304
274
#[ inline( always) ]
305
275
pure fn iter ( & self , f : fn ( x : & T ) ) { iter ( self , f) }
@@ -331,17 +301,6 @@ impl<T> Option<T> {
331
301
#[ inline( always) ]
332
302
pure fn unwrap ( self ) -> T { unwrap ( self ) }
333
303
334
- /**
335
- * The option dance. Moves a value out of an option type and returns it,
336
- * replacing the original with `None`.
337
- *
338
- * # Failure
339
- *
340
- * Fails if the value equals `None`.
341
- */
342
- #[ inline( always) ]
343
- fn swap_unwrap ( & mut self ) -> T { swap_unwrap ( self ) }
344
-
345
304
/**
346
305
* Gets the value out of an option, printing a specified message on
347
306
* failure
0 commit comments