@@ -14,21 +14,27 @@ pub use visitors::VisitExt;
14
14
15
15
/// An copy of the unstable `std::ops::ControlFlow` for use in Chalk visitors.
16
16
pub enum ControlFlow < B , C = ( ) > {
17
+ /// Continue in the loop, using the given value for the next iteration
17
18
Continue ( C ) ,
19
+ /// Exit the loop, yielding the given value
18
20
Break ( B ) ,
19
21
}
20
22
21
23
impl < B , C > ControlFlow < B , C > {
24
+ /// Returns `true` if this is a `Break` variant.
22
25
#[ inline]
23
26
pub fn is_break ( & self ) -> bool {
24
27
matches ! ( * self , ControlFlow :: Break ( _) )
25
28
}
26
29
30
+ /// Returns `true` if this is a `Continue` variant.
27
31
#[ inline]
28
32
pub fn is_continue ( & self ) -> bool {
29
33
matches ! ( * self , ControlFlow :: Continue ( _) )
30
34
}
31
35
36
+ /// Converts the `ControlFlow` into an `Option` which is `Some`
37
+ /// if the `ControlFlow` was `Break` and `None` otherwise.
32
38
#[ inline]
33
39
pub fn break_value ( self ) -> Option < B > {
34
40
match self {
@@ -39,13 +45,20 @@ impl<B, C> ControlFlow<B, C> {
39
45
}
40
46
41
47
impl < B > ControlFlow < B , ( ) > {
48
+ /// It's frequently the case that there's no value needed with `Continue`,
49
+ /// so this provides a way to avoid typing `(())`, if you prefer it.
42
50
pub const CONTINUE : Self = ControlFlow :: Continue ( ( ) ) ;
43
51
}
44
52
45
53
impl < C > ControlFlow < ( ) , C > {
54
+ /// APIs like `try_for_each` don't need values with `Break`,
55
+ /// so this provides a way to avoid typing `(())`, if you prefer it.
46
56
pub const BREAK : Self = ControlFlow :: Break ( ( ) ) ;
47
57
}
48
58
59
+ /// Unwraps a `ControlFlow` or propagates its `Break` value.
60
+ /// This replaces the `Try` implementation that would be used
61
+ /// with `std::ops::ControlFlow`.
49
62
#[ macro_export]
50
63
macro_rules! try_break {
51
64
( $expr: expr) => {
0 commit comments