diff options
| -rw-r--r-- | src/libcore/option.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 21581297894..6a5e90c58ad 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -277,6 +277,13 @@ impl<T> Option<T> { map_default(self, move def, f) } + /// As `map_default`, but consumes the option and gives `f` + /// ownership to avoid copying. + #[inline(always)] + pure fn map_consume_default<U>(self, def: U, f: fn(v: T) -> U) -> U { + match self { None => def, Some(v) => f(v) } + } + /// Performs an operation on the contained value by reference #[inline(always)] pure fn iter(&self, f: fn(x: &T)) { iter(self, f) } |
