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 @@ -89,6 +89,29 @@ impl CfgExpr {
8989 CfgExpr :: Value ( ref e) => cfg. contains ( e) ,
9090 }
9191 }
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+ }
92115}
93116
94117impl FromStr for CfgExpr {
You can’t perform that action at this time.
0 commit comments