SetOps

Trait SetOps 

Source
pub trait SetOps<T>: Bounded<T> {
    // Provided methods
    fn difference<R>(self, other: R) -> Result<OneOrPair<Self>, (Self, R)>
       where T: Ord,
             Self: From<Self::Error>,
             R: IntoBounds<T> + From<<R as IntoBounds<T>>::Error>,
             for<'a> &'a Self: IntoBounds<&'a T>,
             for<'a> &'a R: IntoBounds<&'a T> { ... }
    fn symmetric_difference<R>(self, other: R) -> Result<OneOrPair<Self>, R>
       where T: Ord,
             Self: From<Self::Error>,
             R: IntoBounds<T> + From<<R as IntoBounds<T>>::Error>,
             for<'a> &'a Self: IntoBounds<&'a T>,
             for<'a> &'a R: IntoBounds<&'a T> { ... }
    fn intersect<R>(self, other: R) -> Result<Self, R>
       where T: Ord,
             Self: From<Self::Error>,
             R: IntoBounds<T> + From<R::Error> { ... }
    fn union<R>(self, other: R) -> OneOrPair<Self>
       where T: Ord,
             Self: From<Self::Error>,
             R: IntoBounds<T> + From<R::Error> { ... }
    fn enclosure<R>(self, other: R) -> Self
       where T: Ord,
             Self: From<Self::Error>,
             R: IntoBounds<T> + From<R::Error> { ... }
    fn is_disjoint<'a, R>(&'a self, other: R) -> bool
       where T: Ord + 'a,
             &'a Self: IntoBounds<&'a T>,
             R: IntoBounds<&'a T> { ... }
    fn is_sub<'a, R>(&'a self, other: R) -> bool
       where T: PartialOrd + 'a,
             &'a Self: IntoBounds<&'a T>,
             R: IntoBounds<&'a T> { ... }
    fn is_super<'a, R>(&'a self, other: R) -> bool
       where T: PartialOrd + 'a,
             &'a Self: IntoBounds<&'a T>,
             R: IntoBounds<&'a T> { ... }
}
Expand description

Provides a bunch of set operations for Bounded types.

Provided Methods§

Source

fn difference<R>(self, other: R) -> Result<OneOrPair<Self>, (Self, R)>
where T: Ord, Self: From<Self::Error>, R: IntoBounds<T> + From<<R as IntoBounds<T>>::Error>, for<'a> &'a Self: IntoBounds<&'a T>, for<'a> &'a R: IntoBounds<&'a T>,

Get the set difference between self and other i.e. the span(s) of values that are in self but not in other.

§Errors

Return Err((self, other)) if self is a (not degenerate) subset of other. In this case it is safe to assume the difference is degenerate.

Source

fn symmetric_difference<R>(self, other: R) -> Result<OneOrPair<Self>, R>
where T: Ord, Self: From<Self::Error>, R: IntoBounds<T> + From<<R as IntoBounds<T>>::Error>, for<'a> &'a Self: IntoBounds<&'a T>, for<'a> &'a R: IntoBounds<&'a T>,

Get the symmetric difference between self and other i.e. the span(s) of values that are in one of the intervals but not in other.

§Notes

When the inputs do not overlap, the result is equivalent to their union.

§Errors

Return other if the inputs are equal and not degenerate. In this case it is safe to assume the symmetric difference is degenerate.

Is is tempting here to make the return type Result<_, Self>, because it is very easy for the Err branch to convert the R into Self, but this can lead to accident use of .unwrap_or_else(OneOrPair::One) which is not correct: the Err data is here only for diagnostic use and should be fallen back with manually constructed degenerate interval.

Source

fn intersect<R>(self, other: R) -> Result<Self, R>
where T: Ord, Self: From<Self::Error>, R: IntoBounds<T> + From<R::Error>,

Compute the intersection of self and other.

§Notes

If the self is degenerate, just return it as is.

§Errors

Return other if it is degenerate (for the normal self). In this case it is safe to assume the intersection is degenerate.

Source

fn union<R>(self, other: R) -> OneOrPair<Self>
where T: Ord, Self: From<Self::Error>, R: IntoBounds<T> + From<R::Error>,

The smallest span containing both self and other if the values intersects (wrapped in OneOrPair::One).

Otherwise (when the intervals are disjoint), return a pair of pairs of ordered ranges

§Notes

If at least one of IntoBounds::into_bounds fails (the value is degenerate), return the other value wrapped in OneOrPair::One.

Source

fn enclosure<R>(self, other: R) -> Self
where T: Ord, Self: From<Self::Error>, R: IntoBounds<T> + From<R::Error>,

The smallest span containing both self and other, also covering possible ‘gap’ between them.

§Notes

If at least one of IntoBounds::into_bounds fails (the value is degenerate), return the other value wrapped in OneOrPair::One.

Source

fn is_disjoint<'a, R>(&'a self, other: R) -> bool
where T: Ord + 'a, &'a Self: IntoBounds<&'a T>, R: IntoBounds<&'a T>,

Returns true if there is a non-empty gap between self and other. This implies the self.union(other) guaranteed to be a whole span without jumps

This is not equivalent to checking for an empty intersection. because two intervals can ‘touch’ at a single point, where one of them includes the point and another exclusively approaches it (open interval). This case is considered as not disjoint (i.e. joint), because there is no gap between the intervals, even though their intersection is empty.

Source

fn is_sub<'a, R>(&'a self, other: R) -> bool
where T: PartialOrd + 'a, &'a Self: IntoBounds<&'a T>, R: IntoBounds<&'a T>,

Returns true if the interval lies completely within another, i.e., other contains at least all the values in self.

Source

fn is_super<'a, R>(&'a self, other: R) -> bool
where T: PartialOrd + 'a, &'a Self: IntoBounds<&'a T>, R: IntoBounds<&'a T>,

Returns true if the interval completely contains another, i.e., self contains at least all the values in other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, X> SetOps<T> for X
where X: Bounded<T> + From<Self::Error>,