Skip to content

Commit 65a0125

Browse files
committed
add Option map_consume_default method
1 parent a33966b commit 65a0125

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libcore/option.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ impl<T> Option<T> {
277277
map_default(self, move def, f)
278278
}
279279

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+
280287
/// Performs an operation on the contained value by reference
281288
#[inline(always)]
282289
pure fn iter(&self, f: fn(x: &T)) { iter(self, f) }

0 commit comments

Comments
 (0)