libcore: Implement result::get_ref.

This can be more efficient than unwrapping for large structural
types.
This commit is contained in:
Patrick Walton 2012-08-26 11:50:21 -07:00
parent 62be878ed1
commit 77b8144295

View file

@ -26,6 +26,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
*