make Result::map_or_else consistent with Option::map_or_else
This commit is contained in:
@@ -540,8 +540,11 @@ impl<T, E> Result<T, E> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "result_map_or_else", issue = "53268")]
|
||||
pub fn map_or_else<U, M: FnOnce(T) -> U, F: FnOnce(E) -> U>(self, fallback: F, map: M) -> U {
|
||||
self.map(map).unwrap_or_else(fallback)
|
||||
pub fn map_or_else<U, D: FnOnce(E) -> U, F: FnOnce(T) -> U>(self, default: D, f: F) -> U {
|
||||
match self {
|
||||
Ok(t) => f(t),
|
||||
Err(e) => default(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a
|
||||
|
||||
Reference in New Issue
Block a user