Skip to content

Commit 1c4a9b9

Browse files
committed
auto merge of #14294 : kballard/rust/result_unwrap_or_else, r=alexcrichton
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]
2 parents 44fcf46 + 2446827 commit 1c4a9b9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/libcore/result.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,19 @@ impl<T, E> Result<T, E> {
508508
/// Unwraps a result, yielding the content of an `Ok`.
509509
/// If the value is an `Err` then it calls `op` with its value.
510510
#[inline]
511-
pub fn unwrap_or_handle(self, op: |E| -> T) -> T {
511+
pub fn unwrap_or_else(self, op: |E| -> T) -> T {
512512
match self {
513513
Ok(t) => t,
514514
Err(e) => op(e)
515515
}
516516
}
517+
518+
/// Deprecated name for `unwrap_or_else()`.
519+
#[deprecated = "replaced by .unwrap_or_else()"]
520+
#[inline]
521+
pub fn unwrap_or_handle(self, op: |E| -> T) -> T {
522+
self.unwrap_or_else(op)
523+
}
517524
}
518525

519526
impl<T, E: Show> Result<T, E> {
@@ -758,8 +765,8 @@ mod tests {
758765
let ok: Result<int, ~str> = Ok(100);
759766
let ok_err: Result<int, ~str> = Err("I got this.".to_owned());
760767

761-
assert_eq!(ok.unwrap_or_handle(handler), 100);
762-
assert_eq!(ok_err.unwrap_or_handle(handler), 50);
768+
assert_eq!(ok.unwrap_or_else(handler), 100);
769+
assert_eq!(ok_err.unwrap_or_else(handler), 50);
763770
}
764771

765772
#[test]
@@ -774,6 +781,6 @@ mod tests {
774781
}
775782

776783
let bad_err: Result<int, ~str> = Err("Unrecoverable mess.".to_owned());
777-
let _ : int = bad_err.unwrap_or_handle(handler);
784+
let _ : int = bad_err.unwrap_or_else(handler);
778785
}
779786
}

0 commit comments

Comments
 (0)