From 24468278fd0b6c09d3b105dd2dfc56e7066b961b Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 19 May 2014 13:11:49 -0700 Subject: [PATCH] Rename Result.unwrap_or_handle() to .unwrap_or_else() Result.unwrap_or_handle() is the equivalent of Option.unwrap_or_else(). In the interests of naming consistency, call it the same thing. [breaking-change] --- src/libcore/result.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 3237269e4a64f..46f4427e8387e 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -508,12 +508,19 @@ impl Result { /// Unwraps a result, yielding the content of an `Ok`. /// If the value is an `Err` then it calls `op` with its value. #[inline] - pub fn unwrap_or_handle(self, op: |E| -> T) -> T { + pub fn unwrap_or_else(self, op: |E| -> T) -> T { match self { Ok(t) => t, Err(e) => op(e) } } + + /// Deprecated name for `unwrap_or_else()`. + #[deprecated = "replaced by .unwrap_or_else()"] + #[inline] + pub fn unwrap_or_handle(self, op: |E| -> T) -> T { + self.unwrap_or_else(op) + } } impl Result { @@ -758,8 +765,8 @@ mod tests { let ok: Result = Ok(100); let ok_err: Result = Err("I got this.".to_owned()); - assert_eq!(ok.unwrap_or_handle(handler), 100); - assert_eq!(ok_err.unwrap_or_handle(handler), 50); + assert_eq!(ok.unwrap_or_else(handler), 100); + assert_eq!(ok_err.unwrap_or_else(handler), 50); } #[test] @@ -774,6 +781,6 @@ mod tests { } let bad_err: Result = Err("Unrecoverable mess.".to_owned()); - let _ : int = bad_err.unwrap_or_handle(handler); + let _ : int = bad_err.unwrap_or_else(handler); } }