Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0272ab0

Browse files
jhprattgitbot
authored and
gitbot
committedMar 11, 2025
Rollup merge of rust-lang#137495 - madhav-madhusoodanan:feature-unstable-control-flow-into-value, r=jhpratt
Added into_value function to ControlFlow<T, T>
2 parents aac9abe + a648e8d commit 0272ab0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎core/src/ops/control_flow.rs

+21
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,27 @@ impl<B, C> ControlFlow<B, C> {
229229
}
230230
}
231231

232+
impl<T> ControlFlow<T, T> {
233+
/// Extracts the value `T` that is wrapped by `ControlFlow<T, T>`.
234+
///
235+
/// # Examples
236+
///
237+
/// ```
238+
/// #![feature(control_flow_into_value)]
239+
/// use std::ops::ControlFlow;
240+
///
241+
/// assert_eq!(ControlFlow::<i32, i32>::Break(1024).into_value(), 1024);
242+
/// assert_eq!(ControlFlow::<i32, i32>::Continue(512).into_value(), 512);
243+
/// ```
244+
#[unstable(feature = "control_flow_into_value", issue = "137461")]
245+
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
246+
pub const fn into_value(self) -> T {
247+
match self {
248+
ControlFlow::Continue(x) | ControlFlow::Break(x) => x,
249+
}
250+
}
251+
}
252+
232253
/// These are used only as part of implementing the iterator adapters.
233254
/// They have mediocre names and non-obvious semantics, so aren't
234255
/// currently on a path to potential stabilization.

0 commit comments

Comments
 (0)
Please sign in to comment.