@@ -118,13 +118,13 @@ impl<T> Option<T> {
118
118
}
119
119
}
120
120
121
- /// Returns true if the option equals `none `
121
+ /// Returns true if the option equals `None `
122
122
#[ inline]
123
123
pub fn is_none ( & self ) -> bool {
124
124
match * self { None => true , Some ( _) => false }
125
125
}
126
126
127
- /// Returns true if the option contains some value
127
+ /// Returns true if the option contains a `Some` value
128
128
#[ inline]
129
129
pub fn is_some ( & self ) -> bool { !self . is_none ( ) }
130
130
@@ -158,6 +158,17 @@ impl<T> Option<T> {
158
158
}
159
159
}
160
160
161
+ /// Update an optional value by optionally running its content by mut reference
162
+ /// through a function that returns an option.
163
+ #[ inline]
164
+ pub fn chain_mut_ref < ' a , U > ( & ' a mut self , f : & fn ( x : & ' a mut T ) -> Option < U > )
165
+ -> Option < U > {
166
+ match * self {
167
+ Some ( ref mut x) => f ( x) ,
168
+ None => None
169
+ }
170
+ }
171
+
161
172
/// Filters an optional value using given function.
162
173
#[ inline( always) ]
163
174
pub fn filtered ( self , f : & fn ( t : & T ) -> bool ) -> Option < T > {
@@ -167,19 +178,19 @@ impl<T> Option<T> {
167
178
}
168
179
}
169
180
170
- /// Maps a `some ` value from one type to another by reference
181
+ /// Maps a `Some ` value from one type to another by reference
171
182
#[ inline]
172
183
pub fn map < ' a , U > ( & ' a self , f : & fn ( & ' a T ) -> U ) -> Option < U > {
173
184
match * self { Some ( ref x) => Some ( f ( x) ) , None => None }
174
185
}
175
186
176
- /// Maps a `some ` value from one type to another by a mutable reference
187
+ /// Maps a `Some ` value from one type to another by a mutable reference
177
188
#[ inline]
178
189
pub fn map_mut < ' a , U > ( & ' a mut self , f : & fn ( & ' a mut T ) -> U ) -> Option < U > {
179
190
match * self { Some ( ref mut x) => Some ( f ( x) ) , None => None }
180
191
}
181
192
182
- /// Maps a `some ` value from one type to another by a mutable reference,
193
+ /// Maps a `Some ` value from one type to another by a mutable reference,
183
194
/// or returns a default value.
184
195
#[ inline]
185
196
pub fn map_mut_default < ' a , U > ( & ' a mut self , def : U , f : & fn ( & ' a mut T ) -> U ) -> U {
@@ -260,7 +271,7 @@ impl<T> Option<T> {
260
271
pub fn get_ref < ' a > ( & ' a self ) -> & ' a T {
261
272
match * self {
262
273
Some ( ref x) => x,
263
- None => fail ! ( "option::get_ref none " )
274
+ None => fail ! ( "option::get_ref None " )
264
275
}
265
276
}
266
277
@@ -282,7 +293,7 @@ impl<T> Option<T> {
282
293
pub fn get_mut_ref < ' a > ( & ' a mut self ) -> & ' a mut T {
283
294
match * self {
284
295
Some ( ref mut x) => x,
285
- None => fail ! ( "option::get_mut_ref none " )
296
+ None => fail ! ( "option::get_mut_ref None " )
286
297
}
287
298
}
288
299
@@ -306,7 +317,7 @@ impl<T> Option<T> {
306
317
*/
307
318
match self {
308
319
Some ( x) => x,
309
- None => fail ! ( "option::unwrap none " )
320
+ None => fail ! ( "option::unwrap None " )
310
321
}
311
322
}
312
323
@@ -320,7 +331,7 @@ impl<T> Option<T> {
320
331
*/
321
332
#[ inline]
322
333
pub fn take_unwrap ( & mut self ) -> T {
323
- if self . is_none ( ) { fail ! ( "option::take_unwrap none " ) }
334
+ if self . is_none ( ) { fail ! ( "option::take_unwrap None " ) }
324
335
self . take ( ) . unwrap ( )
325
336
}
326
337
@@ -330,7 +341,7 @@ impl<T> Option<T> {
330
341
*
331
342
* # Failure
332
343
*
333
- * Fails if the value equals `none `
344
+ * Fails if the value equals `None `
334
345
*/
335
346
#[ inline]
336
347
pub fn expect ( self , reason : & str ) -> T {
@@ -358,7 +369,7 @@ impl<T> Option<T> {
358
369
pub fn get ( self ) -> T {
359
370
match self {
360
371
Some ( x) => return x,
361
- None => fail ! ( "option::get none " )
372
+ None => fail ! ( "option::get None " )
362
373
}
363
374
}
364
375
@@ -368,7 +379,7 @@ impl<T> Option<T> {
368
379
match self { Some ( x) => x, None => def }
369
380
}
370
381
371
- /// Applies a function zero or more times until the result is none .
382
+ /// Applies a function zero or more times until the result is None .
372
383
#[ inline]
373
384
pub fn while_some ( self , blk : & fn ( v : T ) -> Option < T > ) {
374
385
let mut opt = self ;
0 commit comments