Skip to content

Commit f7c6f86

Browse files
committed
core: Add Result.get_ref method
1 parent a605416 commit f7c6f86

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libcore/result.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ pub fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn((&E)) -> F)
204204
}
205205

206206
impl<T, E> Result<T, E> {
207+
fn get_ref(&self) -> &self/T { get_ref(self) }
208+
207209
fn is_ok() -> bool { is_ok(&self) }
208210

209211
fn is_err() -> bool { is_err(&self) }
@@ -436,4 +438,10 @@ mod tests {
436438
assert Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a");
437439
assert Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b");
438440
}
441+
442+
#[test]
443+
fn test_get_ref_method() {
444+
let foo: Result<int, ()> = Ok(100);
445+
assert *foo.get_ref() == 100;
446+
}
439447
}

0 commit comments

Comments
 (0)