Added into_value const function to ControlFlow<T, T>
Fixed issue with usage of generics and moved feature gate to crate root Removed const tag Fixed alphabetical ordering of feature gate, added same to doctest Removed crate-level declaration of feature gate control_flow_into_value Used const_precise_live_drops to constify into_value without issue of a drop
This commit is contained in:
parent
b522e7c5ea
commit
f49b6c6cd5
@ -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.
|
/// These are used only as part of implementing the iterator adapters.
|
||||||
/// They have mediocre names and non-obvious semantics, so aren't
|
/// They have mediocre names and non-obvious semantics, so aren't
|
||||||
/// currently on a path to potential stabilization.
|
/// currently on a path to potential stabilization.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user