| 79 | } |
| 80 | |
| 81 | fn intersect(self, other: Values<'a>) -> Values<'a> { |
| 82 | match (self, other) { |
| 83 | (Values::Empty, _) => Values::Empty, |
| 84 | (_, Values::Empty) => Values::Empty, |
| 85 | (Values::Within(a0, a1), Values::Within(b0, b1)) => { |
| 86 | let min = a0.max(b0); |
| 87 | let max = a1.min(b1); |
| 88 | if min <= max { |
| 89 | Values::Within(min, max) |
| 90 | } else { |
| 91 | Values::Empty |
| 92 | } |
| 93 | } |
| 94 | (Values::Nested(mut a), Values::Nested(b)) => { |
| 95 | for (datum, other_spec) in b { |
| 96 | let spec = a.entry(datum).or_insert_with(ResultSpec::anything); |
| 97 | *spec = spec.clone().intersect(other_spec); |
| 98 | } |
| 99 | Values::Nested(a) |
| 100 | } |
| 101 | (Values::All, v) => v, |
| 102 | (v, Values::All) => v, |
| 103 | (Values::Nested(_), Values::Within(_, _)) => Values::Empty, |
| 104 | (Values::Within(_, _), Values::Nested(_)) => Values::Empty, |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | fn may_contain(&self, value: Datum<'a>) -> bool { |
| 109 | match self { |