Decide if this interval contains a [`ScalarValue`] (`other`) by returning `true` or `false`.
(&self, other: T)
| 710 | |
| 711 | /// Decide if this interval contains a [`ScalarValue`] (`other`) by returning `true` or `false`. |
| 712 | pub fn contains_value<T: Borrow<ScalarValue>>(&self, other: T) -> Result<bool> { |
| 713 | let rhs = other.borrow(); |
| 714 | |
| 715 | let (lhs_lower, lhs_upper, rhs_value) = if self.data_type().eq(&rhs.data_type()) { |
| 716 | (self.lower.clone(), self.upper.clone(), rhs.clone()) |
| 717 | } else { |
| 718 | let maybe_common_type = |
| 719 | comparison_coercion(&self.data_type(), &rhs.data_type()); |
| 720 | assert_or_internal_err!( |
| 721 | maybe_common_type.is_some(), |
| 722 | "Data types must be compatible for containment checks, lhs:{}, rhs:{}", |
| 723 | self.data_type(), |
| 724 | rhs.data_type() |
| 725 | ); |
| 726 | let common_type = maybe_common_type.expect("checked for Some"); |
| 727 | ( |
| 728 | self.lower.cast_to(&common_type)?, |
| 729 | self.upper.cast_to(&common_type)?, |
| 730 | rhs.cast_to(&common_type)?, |
| 731 | ) |
| 732 | }; |
| 733 | |
| 734 | // We only check the upper bound for a `None` value because `None` |
| 735 | // values are less than `Some` values according to Rust. |
| 736 | Ok(lhs_lower <= rhs_value && (lhs_upper.is_null() || rhs_value <= lhs_upper)) |
| 737 | } |
| 738 | |
| 739 | /// Decide if this interval is a superset of, overlaps with, or |
| 740 | /// disjoint with `other` by returning `[true, true]`, `[false, true]` or |