]> git.lizzy.rs Git - rust.git/commitdiff
core: Add Result.get_ref method
authorBrian Anderson <banderson@mozilla.com>
Tue, 23 Oct 2012 01:31:13 +0000 (18:31 -0700)
committerBrian Anderson <banderson@mozilla.com>
Tue, 23 Oct 2012 01:31:22 +0000 (18:31 -0700)
src/libcore/result.rs

index 06d8c0da0d0134ea622c51c07be5fd9d3fbb7763..3015e893700c1be3463b087f514b561f542503ac 100644 (file)
@@ -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 @@ fn test_impl_map_err() {
         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;
+    }
 }