about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-08-26 11:50:21 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-08-26 11:50:21 -0700
commit77b8144295fdc19bf7700e3db9551fd190ecebcb (patch)
tree33efcd6867a109f595f1dfd42912e04e953f19fb /src
parent62be878ed1715650f080c3b113a85f73e7af0973 (diff)
downloadrust-77b8144295fdc19bf7700e3db9551fd190ecebcb.tar.gz
rust-77b8144295fdc19bf7700e3db9551fd190ecebcb.zip
libcore: Implement result::get_ref.
This can be more efficient than unwrapping for large structural
types.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/result.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 9b8482c5b5c..e916a28ea79 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -27,6 +27,22 @@ pure fn get<T: copy, U>(res: result<T, U>) -> T {
 }
 
 /**
+ * Get a reference to the value out of a successful result
+ *
+ * # Failure
+ *
+ * If the result is an error
+ */
+pure fn get_ref<T, U>(res: &a/result<T, U>) -> &a/T {
+    match *res {
+        ok(ref t) => t,
+        err(ref the_err) => unchecked {
+            fail fmt!("get_ref called on error result: %?", the_err)
+        }
+    }
+}
+
+/**
  * Get the value out of an error result
  *
  * # Failure