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