libcore: Implement result::get_ref.
This can be more efficient than unwrapping for large structural types.
This commit is contained in:
parent
62be878ed1
commit
77b8144295
1 changed files with 16 additions and 0 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue