File tree 1 file changed +23
-0
lines changed
crates/cargo-platform/src
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,29 @@ impl CfgExpr {
89
89
CfgExpr :: Value ( ref e) => cfg. contains ( e) ,
90
90
}
91
91
}
92
+
93
+ /// Walk over all the `CfgExpr`s of the given `CfgExpr`, recursing into `not(...)`, `all(...)`,
94
+ /// `any(...)` and stopping at the first error and returning that error.
95
+ pub fn walk_expr < E > ( & self , mut f : impl FnMut ( & CfgExpr ) -> Result < ( ) , E > ) -> Result < ( ) , E > {
96
+ fn walk_expr_inner < E > (
97
+ cfg_expr : & CfgExpr ,
98
+ f : & mut impl FnMut ( & CfgExpr ) -> Result < ( ) , E > ,
99
+ ) -> Result < ( ) , E > {
100
+ f ( cfg_expr) ?;
101
+ match * cfg_expr {
102
+ CfgExpr :: Not ( ref e) => walk_expr_inner ( e, & mut * f) ,
103
+ CfgExpr :: All ( ref e) | CfgExpr :: Any ( ref e) => {
104
+ for e in e {
105
+ let _ = walk_expr_inner ( e, & mut * f) ?;
106
+ }
107
+ Ok ( ( ) )
108
+ }
109
+ CfgExpr :: Value ( _) => Ok ( ( ) ) ,
110
+ }
111
+ }
112
+
113
+ walk_expr_inner ( self , & mut f)
114
+ }
92
115
}
93
116
94
117
impl FromStr for CfgExpr {
You can’t perform that action at this time.
0 commit comments