about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2014-05-19 13:11:49 -0700
committerKevin Ballard <kevin@sb.org>2014-05-19 13:11:49 -0700
commit24468278fd0b6c09d3b105dd2dfc56e7066b961b (patch)
treea96cdd893f9f6518ede6830dcfef85101357a4e5
parente8c579e01d026df002fe6522d6f9c123b3920dc8 (diff)
downloadrust-24468278fd0b6c09d3b105dd2dfc56e7066b961b.tar.gz
rust-24468278fd0b6c09d3b105dd2dfc56e7066b961b.zip
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]
-rw-r--r--src/libcore/result.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 3237269e4a6..46f4427e838 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -508,12 +508,19 @@ impl<T, E> Result<T, E> {
     /// 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<T, E: Show> Result<T, E> {
@@ -758,8 +765,8 @@ mod tests {
         let ok: Result<int, ~str> = Ok(100);
         let ok_err: Result<int, ~str> = 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<int, ~str> = Err("Unrecoverable mess.".to_owned());
-        let _ : int = bad_err.unwrap_or_handle(handler);
+        let _ : int = bad_err.unwrap_or_else(handler);
     }
 }