Skip to content

Commit b850eb1

Browse files
committed
---
yaml --- r: 67078 b: refs/heads/master c: 5a9b33a h: refs/heads/master v: v3
1 parent d268850 commit b850eb1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 96c1082f0fdbbe5258cfc1dc37f83052feff8421
2+
refs/heads/master: 5a9b33a76d76a77d2ced1c2430a25faa0f284071
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libstd/option.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ impl<T> Option<T> {
200200
match self { None => def, Some(v) => f(v) }
201201
}
202202

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+
203217
/// Apply a function to the contained value or do nothing
204218
pub fn mutate(&mut self, f: &fn(T) -> T) {
205219
if self.is_some() {

0 commit comments

Comments
 (0)