Skip to content

Commit 7d761fe

Browse files
committed
Auto merge of #66322 - lzutao:consistent-result-map_or_else, r=dtolnay
Stabilize Result::map_or_else Stabilized this API: ```rust impl<T, E> Result<T, E> { 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), } } } ``` Closes #53268 r? @SimonSapin
2 parents e41ced3 + c06a8ea commit 7d761fe

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libcore/result.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ impl<T, E> Result<T, E> {
551551
/// Basic usage:
552552
///
553553
/// ```
554-
/// #![feature(result_map_or_else)]
555554
/// let k = 21;
556555
///
557556
/// let x : Result<_, &str> = Ok("foo");
@@ -561,9 +560,12 @@ impl<T, E> Result<T, E> {
561560
/// assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42);
562561
/// ```
563562
#[inline]
564-
#[unstable(feature = "result_map_or_else", issue = "53268")]
565-
pub fn map_or_else<U, M: FnOnce(T) -> U, F: FnOnce(E) -> U>(self, fallback: F, map: M) -> U {
566-
self.map(map).unwrap_or_else(fallback)
563+
#[stable(feature = "result_map_or_else", since = "1.41.0")]
564+
pub fn map_or_else<U, D: FnOnce(E) -> U, F: FnOnce(T) -> U>(self, default: D, f: F) -> U {
565+
match self {
566+
Ok(t) => f(t),
567+
Err(e) => default(e),
568+
}
567569
}
568570

569571
/// Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a

0 commit comments

Comments
 (0)