Skip to content

Commit 3afe4ef

Browse files
committed
Auto merge of rust-lang#79773 - lcnr:type-visitor, r=oli-obk
small `TypeVisitor` refactor cc `@LeSeulArtichaut` `@scottmcm` adds `ControlFlow::map_break`
2 parents 4043492 + e0f4b66 commit 3afe4ef

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/src/ops/control_flow.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ impl<B, C> ControlFlow<B, C> {
5656
ControlFlow::Break(x) => Some(x),
5757
}
5858
}
59+
60+
/// Maps `ControlFlow<B, C>` to `ControlFlow<T, C>` by applying a function
61+
/// to the break value in case it exists.
62+
#[inline]
63+
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
64+
pub fn map_break<T, F>(self, f: F) -> ControlFlow<T, C>
65+
where
66+
F: FnOnce(B) -> T,
67+
{
68+
match self {
69+
ControlFlow::Continue(x) => ControlFlow::Continue(x),
70+
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
71+
}
72+
}
5973
}
6074

6175
impl<R: Try> ControlFlow<R, R::Ok> {

0 commit comments

Comments
 (0)