@@ -52,8 +52,10 @@ use crate::{convert, ops};
5252#[ derive( Debug , Clone , Copy , PartialEq ) ]
5353pub enum ControlFlow < B , C = ( ) > {
5454 /// Move on to the next phase of the operation as normal.
55+ #[ cfg_attr( not( bootstrap) , lang = "Continue" ) ]
5556 Continue ( C ) ,
5657 /// Exit the operation without running subsequent phases.
58+ #[ cfg_attr( not( bootstrap) , lang = "Break" ) ]
5759 Break ( B ) ,
5860 // Yes, the order of the variants doesn't match the type parameters.
5961 // They're in this order so that `ControlFlow<A, B>` <-> `Result<B, A>`
@@ -181,6 +183,7 @@ impl<B, C> ControlFlow<B, C> {
181183 }
182184}
183185
186+ #[ cfg( bootstrap) ]
184187impl < R : ops:: TryV1 > ControlFlow < R , R :: Ok > {
185188 /// Create a `ControlFlow` from any type implementing `Try`.
186189 #[ unstable( feature = "control_flow_enum" , reason = "new API" , issue = "75744" ) ]
@@ -203,6 +206,29 @@ impl<R: ops::TryV1> ControlFlow<R, R::Ok> {
203206 }
204207}
205208
209+ #[ cfg( not( bootstrap) ) ]
210+ impl < R : ops:: TryV2 > ControlFlow < R , R :: Output > {
211+ /// Create a `ControlFlow` from any type implementing `Try`.
212+ #[ unstable( feature = "control_flow_enum" , reason = "new API" , issue = "75744" ) ]
213+ #[ inline]
214+ pub fn from_try ( r : R ) -> Self {
215+ match R :: branch ( r) {
216+ ControlFlow :: Continue ( v) => ControlFlow :: Continue ( v) ,
217+ ControlFlow :: Break ( v) => ControlFlow :: Break ( R :: from_residual ( v) ) ,
218+ }
219+ }
220+
221+ /// Convert a `ControlFlow` into any type implementing `Try`;
222+ #[ unstable( feature = "control_flow_enum" , reason = "new API" , issue = "75744" ) ]
223+ #[ inline]
224+ pub fn into_try ( self ) -> R {
225+ match self {
226+ ControlFlow :: Continue ( v) => R :: from_output ( v) ,
227+ ControlFlow :: Break ( v) => v,
228+ }
229+ }
230+ }
231+
206232impl < B > ControlFlow < B , ( ) > {
207233 /// It's frequently the case that there's no value needed with `Continue`,
208234 /// so this provides a way to avoid typing `(())`, if you prefer it.
0 commit comments