about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-01-13 00:56:50 -0500
committerDaniel Micay <danielmicay@gmail.com>2013-01-13 01:37:58 -0500
commit65a0125f7f2e016a066bb3e8944b6ec31d2d46c7 (patch)
tree9f34f6f351c8f7a0e18ffa531cfa6914c85bbeac
parenta33966b2f2a93b5108d0fd4464b18912da270e15 (diff)
downloadrust-65a0125f7f2e016a066bb3e8944b6ec31d2d46c7.tar.gz
rust-65a0125f7f2e016a066bb3e8944b6ec31d2d46c7.zip
add Option map_consume_default method
-rw-r--r--src/libcore/option.rs7
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) }