| 48 | } |
| 49 | |
| 50 | fn union(self, other: Values<'a>) -> Values<'a> { |
| 51 | match (self, other) { |
| 52 | (Values::Empty, r) => r, |
| 53 | (r, Values::Empty) => r, |
| 54 | (Values::Within(a0, a1), Values::Within(b0, b1)) => { |
| 55 | Values::Within(a0.min(b0), a1.max(b1)) |
| 56 | } |
| 57 | (Values::Nested(a), Values::Nested(mut b)) => { |
| 58 | // `Nested(map)` treats keys missing from `map` as fully unconstrained, so a |
| 59 | // key present in only one side of the union must be treated as `anything` |
| 60 | // on the other side. Because `x ∪ anything = anything`, such keys drop |
| 61 | // out of the merged map (the Nested default is already "anything"). |
| 62 | let mut merged = BTreeMap::new(); |
| 63 | for (key, a_spec) in a { |
| 64 | if let Some(b_spec) = b.remove(&key) { |
| 65 | let unioned = a_spec.union(b_spec); |
| 66 | if unioned != ResultSpec::anything() { |
| 67 | merged.insert(key, unioned); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | if merged.is_empty() { |
| 72 | Values::All |
| 73 | } else { |
| 74 | Values::Nested(merged) |
| 75 | } |
| 76 | } |
| 77 | _ => Values::All, |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | fn intersect(self, other: Values<'a>) -> Values<'a> { |
| 82 | match (self, other) { |