about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-26 18:03:44 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-27 23:41:09 -0700
commit4eb95f6d1c22419b50980d0bf8effc6e2f22feb5 (patch)
tree725d52c5e0c06d82b05957a5272a9a909c726a8e /src/libstd
parent225f1c760d998b2f26107c3938d4ca8baa57c6c0 (diff)
downloadrust-4eb95f6d1c22419b50980d0bf8effc6e2f22feb5.tar.gz
rust-4eb95f6d1c22419b50980d0bf8effc6e2f22feb5.zip
cleanup .iter and .iter_err
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/result.rs95
1 files changed, 48 insertions, 47 deletions
diff --git a/src/libstd/result.rs b/src/libstd/result.rs
index 7b660ed8624..809244af12a 100644
--- a/src/libstd/result.rs
+++ b/src/libstd/result.rs
@@ -62,21 +62,6 @@ pub fn get_err<T, U: Clone>(res: &Result<T, U>) -> U {
     }
 }
 
-/// Returns true if the result is `ok`
-#[inline]
-pub fn is_ok<T, U>(res: &Result<T, U>) -> bool {
-    match *res {
-      Ok(_) => true,
-      Err(_) => false
-    }
-}
-
-/// Returns true if the result is `err`
-#[inline]
-pub fn is_err<T, U>(res: &Result<T, U>) -> bool {
-    !is_ok(res)
-}
-
 /**
  * Convert to the `either` type
  *
@@ -134,27 +119,8 @@ pub fn chain_err<T, U, V>(
     }
 }
 
-/**
- * Call a function based on a previous result
- *
- * If `res` is `ok` then the value is extracted and passed to `op` whereupon
- * `op`s result is returned. if `res` is `err` then it is immediately
- * returned. This function can be used to compose the results of two
- * functions.
- *
- * Example:
- *
- *     iter(read_file(file)) { |buf|
- *         print_buf(buf)
- *     }
- */
-#[inline]
-pub fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
-    match *res {
-      Ok(ref t) => f(t),
-      Err(_) => ()
-    }
-}
+
+
 
 /**
  * Call a function based on a previous result
@@ -164,13 +130,7 @@ pub fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
  * This function can be used to pass through a successful result while
  * handling an error.
  */
-#[inline]
-pub fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
-    match *res {
-      Ok(_) => (),
-      Err(ref e) => f(e)
-    }
-}
+
 
 /**
  * Call a function based on a previous result
@@ -229,17 +189,58 @@ impl<T, E> Result<T, E> {
         }
     }
 
+    /// Returns true if the result is `ok`
     #[inline]
-    pub fn is_ok(&self) -> bool { is_ok(self) }
+    pub fn is_ok(&self) -> bool {
+        match *self {
+            Ok(_) => true,
+            Err(_) => false
+        }
+    }
 
+    /// Returns true if the result is `err`
     #[inline]
-    pub fn is_err(&self) -> bool { is_err(self) }
+    pub fn is_err(&self) -> bool {
+        !self.is_ok()
+    }
 
+    /**
+     * Call a function based on a previous result
+     *
+     * If `*self` is `ok` then the value is extracted and passed to `op` whereupon
+     * `op`s result is returned. if `res` is `err` then it is immediately
+     * returned. This function can be used to compose the results of two
+     * functions.
+     *
+     * Example:
+     *
+     *     read_file(file).iter() { |buf|
+     *         print_buf(buf)
+     *     }
+     */
     #[inline]
-    pub fn iter(&self, f: &fn(&T)) { iter(self, f) }
+    pub fn iter(&self, f: &fn(&T)) {
+        match *self {
+            Ok(ref t) => f(t),
+            Err(_) => ()
+        }
+    }
 
+    /**
+     * Call a function based on a previous result
+     *
+     * If `*self` is `err` then the value is extracted and passed to `op` whereupon
+     * `op`s result is returned. if `res` is `ok` then it is immediately returned.
+     * This function can be used to pass through a successful result while
+     * handling an error.
+     */
     #[inline]
-    pub fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
+    pub fn iter_err(&self, f: &fn(&E)) {
+        match *self {
+            Ok(_) => (),
+            Err(ref e) => f(e)
+        }
+    }
 
     #[inline]
     pub fn unwrap(self) -> T { unwrap(self) }