diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-02-24 02:11:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-24 02:11:36 -0500 |
| commit | 3a1549ca8e8cd092c0d8aa143f0e95a2e300bda6 (patch) | |
| tree | f3af10baf866197c1038b4105b88dbfa70d00f0d | |
| parent | e66fcc34107b37062d48264b721fb26cf4895616 (diff) | |
| parent | f49b6c6cd58aa61c804dcb22cc013c728f8924af (diff) | |
| download | rust-3a1549ca8e8cd092c0d8aa143f0e95a2e300bda6.tar.gz rust-3a1549ca8e8cd092c0d8aa143f0e95a2e300bda6.zip | |
Rollup merge of #137495 - madhav-madhusoodanan:feature-unstable-control-flow-into-value, r=jhpratt
Added into_value function to ControlFlow<T, T>
| -rw-r--r-- | library/core/src/ops/control_flow.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index c8fcee5c140..8993e14fcd3 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -229,6 +229,27 @@ impl<B, C> ControlFlow<B, C> { } } +impl<T> ControlFlow<T, T> { + /// Extracts the value `T` that is wrapped by `ControlFlow<T, T>`. + /// + /// # Examples + /// + /// ``` + /// #![feature(control_flow_into_value)] + /// use std::ops::ControlFlow; + /// + /// assert_eq!(ControlFlow::<i32, i32>::Break(1024).into_value(), 1024); + /// assert_eq!(ControlFlow::<i32, i32>::Continue(512).into_value(), 512); + /// ``` + #[unstable(feature = "control_flow_into_value", issue = "137461")] + #[rustc_allow_const_fn_unstable(const_precise_live_drops)] + pub const fn into_value(self) -> T { + match self { + ControlFlow::Continue(x) | ControlFlow::Break(x) => x, + } + } +} + /// These are used only as part of implementing the iterator adapters. /// They have mediocre names and non-obvious semantics, so aren't /// currently on a path to potential stabilization. |
