diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 9b8482c5b5c2..e916a28ea79d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -26,6 +26,22 @@ pure fn get(res: result) -> T { } } +/** + * Get a reference to the value out of a successful result + * + * # Failure + * + * If the result is an error + */ +pure fn get_ref(res: &a/result) -> &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 *