summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-10-11 14:14:46 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-10-11 14:17:59 -0700
commit1ab914df1d24f6c198bb7b1e01a4cf0050d179c8 (patch)
tree7d1e178e44fb48f5951ed8ddc92727b5c722f858 /src/libcore
parent5a8ba073bcd6ee6fd34ff545845a746cddc4904f (diff)
downloadrust-1ab914df1d24f6c198bb7b1e01a4cf0050d179c8.tar.gz
rust-1ab914df1d24f6c198bb7b1e01a4cf0050d179c8.zip
Write option::chain and result::chain with `match move`
Closes #3590
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/option.rs8
-rw-r--r--src/libcore/result.rs8
2 files changed, 6 insertions, 10 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index c60b7b401cc..e970f00c5fb 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -119,11 +119,9 @@ pub pure fn chain<T, U>(opt: Option<T>,
      * function that returns an option.
      */
 
-    // XXX write with move match
-    if opt.is_some() {
-        f(unwrap(opt))
-    } else {
-        None
+    match move opt {
+        Some(move t) => f(t),
+        None => None
     }
 }
 
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 39fae8905f9..611d6239435 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -105,11 +105,9 @@ pub pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>)
  */
 pub fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(t: T)
     -> Result<U, V>) -> Result<U, V> {
-    // XXX: Should be writable with move + match
-    if res.is_ok() {
-        op(unwrap(res))
-    } else {
-        Err(unwrap_err(res))
+    match move res {
+        Ok(move t) => op(t),
+        Err(move e) => Err(e)
     }
 }