1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
mod cfg_expr;
use rustc_hash::FxHashSet;
use tt::SmolStr;
pub use cfg_expr::CfgExpr;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CfgOptions {
atoms: FxHashSet<SmolStr>,
key_values: FxHashSet<(SmolStr, SmolStr)>,
}
impl CfgOptions {
pub fn check(&self, cfg: &CfgExpr) -> Option<bool> {
cfg.fold(&|key, value| match value {
None => self.atoms.contains(key),
Some(value) => self.key_values.contains(&(key.clone(), value.clone())),
})
}
pub fn insert_atom(&mut self, key: SmolStr) {
self.atoms.insert(key);
}
pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) {
self.key_values.insert((key, value));
}
pub fn append(&mut self, other: &CfgOptions) {
for atom in &other.atoms {
self.atoms.insert(atom.clone());
}
for (key, value) in &other.key_values {
self.key_values.insert((key.clone(), value.clone()));
}
}
}