File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
crates/cargo-platform/src Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,29 @@ impl CfgExpr {
153153 CfgExpr :: False => false ,
154154 }
155155 }
156+
157+ /// Walk over all the `Cfg`s of the given `CfgExpr`, recursing into `not(...)`, `all(...)`,
158+ /// `any(...)` and stopping at the first error and returning that error.
159+ pub fn walk < E > ( & self , mut f : impl FnMut ( & Cfg ) -> Result < ( ) , E > ) -> Result < ( ) , E > {
160+ fn walk_inner < E > (
161+ cfg_expr : & CfgExpr ,
162+ f : & mut impl FnMut ( & Cfg ) -> Result < ( ) , E > ,
163+ ) -> Result < ( ) , E > {
164+ match * cfg_expr {
165+ CfgExpr :: Not ( ref e) => walk_inner ( e, & mut * f) ,
166+ CfgExpr :: All ( ref e) | CfgExpr :: Any ( ref e) => {
167+ for e in e {
168+ let _ = walk_inner ( e, & mut * f) ?;
169+ }
170+ Ok ( ( ) )
171+ }
172+ CfgExpr :: Value ( ref e) => f ( e) ,
173+ CfgExpr :: True | CfgExpr :: False => Ok ( ( ) ) ,
174+ }
175+ }
176+
177+ walk_inner ( self , & mut f)
178+ }
156179}
157180
158181impl FromStr for CfgExpr {
You can’t perform that action at this time.
0 commit comments