]> git.lizzy.rs Git - rust.git/blobdiff - library/core/src/ops/control_flow.rs
Auto merge of #79780 - camelid:use-summary_opts, r=GuillaumeGomez
[rust.git] / library / core / src / ops / control_flow.rs
index 5ede1ba8e2c104076aa205dff4ff2edd5e87a738..4834ca74b8270eaf0a09260fc62f10d4880ba387 100644 (file)
@@ -56,6 +56,20 @@ pub fn break_value(self) -> Option<B> {
             ControlFlow::Break(x) => Some(x),
         }
     }
+
+    /// Maps `ControlFlow<B, C>` to `ControlFlow<T, C>` by applying a function
+    /// to the break value in case it exists.
+    #[inline]
+    #[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
+    pub fn map_break<T, F>(self, f: F) -> ControlFlow<T, C>
+    where
+        F: FnOnce(B) -> T,
+    {
+        match self {
+            ControlFlow::Continue(x) => ControlFlow::Continue(x),
+            ControlFlow::Break(x) => ControlFlow::Break(f(x)),
+        }
+    }
 }
 
 impl<R: Try> ControlFlow<R, R::Ok> {