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:57 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-27 23:41:09 -0700
commite308167a2fe558924fcebcc99358c057ae0b90b4 (patch)
tree6e2905fc4a4768bc9952d8e10703d486404b0821 /src/libstd
parent4eb95f6d1c22419b50980d0bf8effc6e2f22feb5 (diff)
downloadrust-e308167a2fe558924fcebcc99358c057ae0b90b4.tar.gz
rust-e308167a2fe558924fcebcc99358c057ae0b90b4.zip
cleanup .unwrap and .unwrap_err fixing io tests
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io.rs6
-rw-r--r--src/libstd/result.rs33
2 files changed, 16 insertions, 23 deletions
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index 05a5184ccba..fcc53c33a5d 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -1851,12 +1851,10 @@ mod tests {
             ~"A hoopy frood who really knows where his towel is.";
         debug!(frood.clone());
         {
-            let out: @io::Writer =
-                result::unwrap(
-                    io::file_writer(tmpfile, [io::Create, io::Truncate]));
+            let out: @io::Writer = io::file_writer(tmpfile, [io::Create, io::Truncate]).unwrap();
             out.write_str(frood);
         }
-        let inp: @io::Reader = result::unwrap(io::file_reader(tmpfile));
+        let inp: @io::Reader = io::file_reader(tmpfile).unwrap();
         let frood2: ~str = inp.read_c_str();
         debug!(frood2.clone());
         assert_eq!(frood, frood2);
diff --git a/src/libstd/result.rs b/src/libstd/result.rs
index 809244af12a..ec2715fcf2e 100644
--- a/src/libstd/result.rs
+++ b/src/libstd/result.rs
@@ -242,11 +242,23 @@ impl<T, E> Result<T, E> {
         }
     }
 
+    /// Unwraps a result, assuming it is an `ok(T)`
     #[inline]
-    pub fn unwrap(self) -> T { unwrap(self) }
+    pub fn unwrap(self) -> T {
+        match self {
+            Ok(t) => t,
+            Err(_) => fail!("unwrap called on an err result")
+        }
+    }
 
+    /// Unwraps a result, assuming it is an `err(U)`
     #[inline]
-    pub fn unwrap_err(self) -> E { unwrap_err(self) }
+    pub fn unwrap_err(self) -> E {
+        match self {
+            Err(u) => u,
+            Ok(_) => fail!("unwrap called on an ok result")
+        }
+    }
 
     #[inline]
     pub fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
@@ -375,23 +387,6 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
     return Ok(());
 }
 
-/// Unwraps a result, assuming it is an `ok(T)`
-#[inline]
-pub fn unwrap<T, U>(res: Result<T, U>) -> T {
-    match res {
-      Ok(t) => t,
-      Err(_) => fail!("unwrap called on an err result")
-    }
-}
-
-/// Unwraps a result, assuming it is an `err(U)`
-#[inline]
-pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
-    match res {
-      Err(u) => u,
-      Ok(_) => fail!("unwrap called on an ok result")
-    }
-}
 
 #[cfg(test)]
 mod tests {