From f7c6f867b378e56b589f0e238913a3818af24816 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 22 Oct 2012 18:31:13 -0700 Subject: [PATCH] core: Add Result.get_ref method --- src/libcore/result.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 06d8c0da0d0..3015e893700 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -204,6 +204,8 @@ pub fn map_err(res: &Result, op: fn((&E)) -> F) } impl Result { + 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 = Ok(100); + assert *foo.get_ref() == 100; + } }