mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
libcore: Implement result::get_ref.
This can be more efficient than unwrapping for large structural types.
This commit is contained in:
@@ -26,6 +26,22 @@ enum result<T, U> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user