diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-08-26 11:50:21 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-08-26 11:50:21 -0700 |
| commit | 77b8144295fdc19bf7700e3db9551fd190ecebcb (patch) | |
| tree | 33efcd6867a109f595f1dfd42912e04e953f19fb /src | |
| parent | 62be878ed1715650f080c3b113a85f73e7af0973 (diff) | |
| download | rust-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.rs | 16 |
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 |
