Skip to content

Commit 77f537a

Browse files
committed
Add utility function to iterate over all cfg in an expr
1 parent eaee77d commit 77f537a

File tree

1 file changed

+13
-0
lines changed
  • crates/cargo-platform/src

1 file changed

+13
-0
lines changed

crates/cargo-platform/src/cfg.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ impl CfgExpr {
8989
CfgExpr::Value(ref e) => cfg.contains(e),
9090
}
9191
}
92+
93+
pub fn fold<E>(&self, f: &impl Fn(&Cfg) -> Result<(), E>) -> Result<(), E> {
94+
match *self {
95+
CfgExpr::Not(ref e) => CfgExpr::fold(e, f),
96+
CfgExpr::All(ref e) | CfgExpr::Any(ref e) => {
97+
for e in e {
98+
let _ = CfgExpr::fold(e, f)?;
99+
}
100+
Ok(())
101+
}
102+
CfgExpr::Value(ref e) => f(e),
103+
}
104+
}
92105
}
93106

94107
impl FromStr for CfgExpr {

0 commit comments

Comments
 (0)