Skip to content

Commit 6d1bc55

Browse files
Added into_value const function to ControlFlow<T, T>
1 parent b522e7c commit 6d1bc55

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/core/src/ops/control_flow.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(control_flow_into_value)]
12
use crate::{convert, ops};
23

34
/// Used to tell an operation whether it should exit early or go on as usual.
@@ -229,6 +230,25 @@ impl<B, C> ControlFlow<B, C> {
229230
}
230231
}
231232

233+
impl<T> ControlFlow<T, T> {
234+
/// Extracts the value `T` that is wrapped by `ControlFlow<T, T>`.
235+
///
236+
/// # Examples
237+
///
238+
/// ```
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+
pub const fn into_value<T>(self) -> T {
246+
match self {
247+
ControlFlow::Continue(x) | ControlFlow::Break(x) => x,
248+
}
249+
}
250+
}
251+
232252
/// These are used only as part of implementing the iterator adapters.
233253
/// They have mediocre names and non-obvious semantics, so aren't
234254
/// currently on a path to potential stabilization.

0 commit comments

Comments
 (0)