Skip to content

Commit e308167

Browse files
committed
cleanup .unwrap and .unwrap_err fixing io tests
1 parent 4eb95f6 commit e308167

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

src/libextra/workcache.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::cell::Cell;
2222
use std::comm::{PortOne, oneshot, send_one, recv_one};
2323
use std::either::{Either, Left, Right};
2424
use std::io;
25-
use std::result;
2625
use std::run;
2726
use std::task;
2827

@@ -208,7 +207,7 @@ fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
208207
// FIXME(#5121)
209208
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
210209
do io::with_str_reader(s) |rdr| {
211-
let j = result::unwrap(json::from_reader(rdr));
210+
let j = json::from_reader(rdr).unwrap();
212211
let mut decoder = json::Decoder(j);
213212
Decodable::decode(&mut decoder)
214213
}

src/libstd/io.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,12 +1851,10 @@ mod tests {
18511851
~"A hoopy frood who really knows where his towel is.";
18521852
debug!(frood.clone());
18531853
{
1854-
let out: @io::Writer =
1855-
result::unwrap(
1856-
io::file_writer(tmpfile, [io::Create, io::Truncate]));
1854+
let out: @io::Writer = io::file_writer(tmpfile, [io::Create, io::Truncate]).unwrap();
18571855
out.write_str(frood);
18581856
}
1859-
let inp: @io::Reader = result::unwrap(io::file_reader(tmpfile));
1857+
let inp: @io::Reader = io::file_reader(tmpfile).unwrap();
18601858
let frood2: ~str = inp.read_c_str();
18611859
debug!(frood2.clone());
18621860
assert_eq!(frood, frood2);

src/libstd/result.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,23 @@ impl<T, E> Result<T, E> {
242242
}
243243
}
244244

245+
/// Unwraps a result, assuming it is an `ok(T)`
245246
#[inline]
246-
pub fn unwrap(self) -> T { unwrap(self) }
247+
pub fn unwrap(self) -> T {
248+
match self {
249+
Ok(t) => t,
250+
Err(_) => fail!("unwrap called on an err result")
251+
}
252+
}
247253

254+
/// Unwraps a result, assuming it is an `err(U)`
248255
#[inline]
249-
pub fn unwrap_err(self) -> E { unwrap_err(self) }
256+
pub fn unwrap_err(self) -> E {
257+
match self {
258+
Err(u) => u,
259+
Ok(_) => fail!("unwrap called on an ok result")
260+
}
261+
}
250262

251263
#[inline]
252264
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],
375387
return Ok(());
376388
}
377389

378-
/// Unwraps a result, assuming it is an `ok(T)`
379-
#[inline]
380-
pub fn unwrap<T, U>(res: Result<T, U>) -> T {
381-
match res {
382-
Ok(t) => t,
383-
Err(_) => fail!("unwrap called on an err result")
384-
}
385-
}
386-
387-
/// Unwraps a result, assuming it is an `err(U)`
388-
#[inline]
389-
pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
390-
match res {
391-
Err(u) => u,
392-
Ok(_) => fail!("unwrap called on an ok result")
393-
}
394-
}
395390

396391
#[cfg(test)]
397392
mod tests {

0 commit comments

Comments
 (0)