]> git.lizzy.rs Git - rust.git/commitdiff
cleanup .unwrap and .unwrap_err fixing io tests
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Sat, 27 Jul 2013 01:03:57 +0000 (18:03 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Sun, 28 Jul 2013 06:41:09 +0000 (23:41 -0700)
src/libextra/workcache.rs
src/libstd/io.rs
src/libstd/result.rs

index 42210d0cd895c392ce8237492f6b1a7e2c527b02..1cabab713b82538910dda54eac97bb072c409082 100644 (file)
@@ -22,7 +22,6 @@
 use std::comm::{PortOne, oneshot, send_one, recv_one};
 use std::either::{Either, Left, Right};
 use std::io;
-use std::result;
 use std::run;
 use std::task;
 
@@ -208,7 +207,7 @@ fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
 // FIXME(#5121)
 fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
     do io::with_str_reader(s) |rdr| {
-        let j = result::unwrap(json::from_reader(rdr));
+        let j = json::from_reader(rdr).unwrap();
         let mut decoder = json::Decoder(j);
         Decodable::decode(&mut decoder)
     }
index 05a5184ccbac8f7be7e6949a2316aa8cc6ad66c5..fcc53c33a5def9074dae82431c9314ec244656dc 100644 (file)
@@ -1851,12 +1851,10 @@ fn test_simple() {
             ~"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);
index 809244af12a0110968260ac816fce8c0f2d1013c..ec2715fcf2e00f378cf8b0fdb78522fb033a245b 100644 (file)
@@ -242,11 +242,23 @@ pub fn iter_err(&self, f: &fn(&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 {