core: Add Result.get_ref method
This commit is contained in:
parent
a605416bb4
commit
f7c6f867b3
@ -204,6 +204,8 @@ pub fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn((&E)) -> F)
|
||||
}
|
||||
|
||||
impl<T, E> Result<T, E> {
|
||||
fn get_ref(&self) -> &self/T { get_ref(self) }
|
||||
|
||||
fn is_ok() -> bool { is_ok(&self) }
|
||||
|
||||
fn is_err() -> bool { is_err(&self) }
|
||||
@ -436,4 +438,10 @@ mod tests {
|
||||
assert Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a");
|
||||
assert Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_ref_method() {
|
||||
let foo: Result<int, ()> = Ok(100);
|
||||
assert *foo.get_ref() == 100;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user