Enum stats_ci::Interval

source ·
pub enum Interval<T> {
    Empty,
    Degenerate(T),
    Concrete {
        left: T,
        right: T,
    },
}
Expand description

Interval over a partially ordered type (NB: floating point numbers are partially ordered because of NaN). The interval is defined by its lower and upper bounds.

Examples

let interval = Interval::new(0., 1.);
assert_eq!(interval.low().unwrap(), 0.);
assert_eq!(interval.high().unwrap(), 1.);
assert!(!interval.is_empty());
assert!(!interval.is_degenerate());
assert!(interval.is_concrete());
assert!(interval.contains(&0.5));
assert!(!interval.contains(&2.));

let interval2: Interval<_> = Interval::from(0..=10);
assert_eq!(interval2.low().unwrap(), 0);
assert_eq!(interval2.high().unwrap(), 10);

Variants§

§

Empty

§

Degenerate(T)

§

Concrete

Fields

§left: T
§right: T

Implementations§

source§

impl<T: PartialOrd> Interval<T>

source

pub fn new(low: T, high: T) -> Self

Create a new interval from its left and right bounds for ordered types with equality.

Examples
let interval = Interval::new(0., 1.);
assert_eq!(interval.low().unwrap(), 0.);
assert_eq!(interval.high().unwrap(), 1.);
assert!(!interval.is_empty());
let interval2 = Interval::new("A", "Z");
assert_eq!(interval2.low().unwrap(), "A");
assert_eq!(interval2.high().unwrap(), "Z");
let interval3 = Interval::new(0, 0_usize);
assert_eq!(interval3.low().unwrap(), 0);
assert_eq!(interval3.high().unwrap(), 0);
assert!(interval3.is_degenerate());
let interval4 = Interval::new(1, 0);
assert!(interval4.is_empty());
source

pub fn contains(&self, x: &T) -> bool

Test whether the interval contains a value.

source

pub fn intersects(&self, other: &Self) -> bool

Test whether the interval intersects another interval.

source

pub fn is_included_in(&self, other: &Self) -> bool

Test whether the interval is included in another interval.

The inclusion is not strict, i.e. an interval is included in itself.

source

pub fn includes(&self, other: &Self) -> bool

Test whether the interval includes another interval.

The inclusion is not strict, i.e. an interval includes itself.

source§

impl<T> Interval<T>

source

pub fn new_unordered_unchecked(left: T, right: T) -> Self

Create a new interval from its left and right bounds for unordered types. The function is unchecked and always results in a concrete interval. NB: this function is not meant for ordered types; in particular for numerical types.

Examples
#[derive(Debug)]
enum Directions { North, South, East, West};
let interval = Interval::new_unordered_unchecked(Directions::North, Directions::West);
assert!(matches!(interval.left().unwrap(), Directions::North));
assert!(matches!(interval.right().unwrap(), Directions::West));
assert!(!interval.is_empty());
assert!(!interval.is_degenerate());
assert!(interval.is_concrete());
let interval = Interval::new_unordered_unchecked(Directions::North, Directions::North);
// NB: the interval is not degenerate because the bounds equality is not checked
assert!(!interval.is_degenerate());
source

pub fn is_empty(&self) -> bool

Test if the interval is empty.

source

pub fn is_degenerate(&self) -> bool

Test if the interval is degenerate, in the sense that it contains a single element.

source

pub fn is_concrete(&self) -> bool

Test if the interval is concrete, in the sense that it contains at least two elements.

source

pub fn left(&self) -> Option<&T>

Get the left bound of the interval (if any).

source

pub fn right(&self) -> Option<&T>

Get the right bound of the interval (if any).

source§

impl<T: PartialOrd + Clone> Interval<T>

source

pub fn low(&self) -> Option<T>

Get the lower bound of the interval (if any) for partially ordered types.

This function clones the bound. If cloning is an issue, use Self::low_as_ref() instead.

source

pub fn high(&self) -> Option<T>

Get the upper bound of the interval (if any) for partially ordered types.

This function clones the bound. If cloning is an issue, use Self::high_as_ref() instead.

source§

impl<T: PartialOrd> Interval<T>

source

pub fn low_as_ref(&self) -> Option<&T>

Get a reference to the lower bound of the interval (if any) for ordered types.

See also Self::low() if cloning is not an issue.

source

pub fn high_as_ref(&self) -> Option<&T>

Get a reference to the upper bound of the interval (if any) for ordered types.

See also Self::high() if cloning is not an issue.

source§

impl<T: PartialEq> Interval<T>

source

pub fn new_unordered(left: T, right: T) -> Self

Create a new interval from its left and right bounds for unordered types with equality.

Examples
#[derive(Debug, PartialEq)]
enum Directions { North, South, East, West};
let interval = Interval::new_unordered(Directions::North, Directions::West);
assert_eq!(interval.left().unwrap(), &Directions::North);
assert_eq!(interval.right().unwrap(), &Directions::West);
assert!(!interval.is_empty());
assert!(!interval.is_degenerate());
assert!(interval.is_concrete());
let interval = Interval::new_unordered(Directions::North, Directions::North);
assert!(interval.is_degenerate());
source§

impl<T: Sub<Output = T> + Zero + Clone> Interval<T>

source

pub fn width(&self) -> Option<T>

Trait Implementations§

source§

impl<T> AsRef<Interval<T>> for Interval<T>

source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Clone> Clone for Interval<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Interval<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for Interval<T>

source§

fn default() -> Interval<T>

Returns the “default value” for a type. Read more
source§

impl<T: Display> Display for Interval<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: PartialOrd> From<(Option<T>, Option<T>)> for Interval<T>

source§

fn from((low, high): (Option<T>, Option<T>)) -> Self

Converts to this type from the input type.
source§

impl<T: PartialOrd> From<(T, T)> for Interval<T>

source§

fn from((low, high): (T, T)) -> Self

Converts to this type from the input type.
source§

impl<T: PartialOrd + Clone> From<Interval<T>> for (Option<T>, Option<T>)

source§

fn from(interval: Interval<T>) -> Self

Converts to this type from the input type.
source§

impl<T: PartialOrd + Clone> From<Interval<T>> for Option<(T, T)>

source§

fn from(interval: Interval<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Ord> From<RangeInclusive<T>> for Interval<T>

source§

fn from(range: RangeInclusive<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Interval<T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: PartialEq> PartialEq<Interval<T>> for Interval<T>

source§

fn eq(&self, other: &Interval<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd> PartialOrd<Interval<T>> for Interval<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

compare two intervals. given two intervals a and b, a < b if and only if the upper bound of a is less than the lower bound of b. recall that interval bounds are assumed inclusive.

Examples
let a = Interval::new(0, 10);
let b = Interval::new(10, 20);
let c = Interval::new(11, 20);
let d = Interval::new(0, 10);
assert_eq!(a.partial_cmp(&b), None);
assert_eq!(a.partial_cmp(&c), Some(Ordering::Less));
assert_eq!(c.partial_cmp(&a), Some(Ordering::Greater));
assert_eq!(a.partial_cmp(&d), Some(Ordering::Equal));
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: PartialOrd> RangeBounds<T> for Interval<T>

source§

fn start_bound(&self) -> Bound<&T>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&T>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> boolwhere T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl<T: Copy> Copy for Interval<T>

source§

impl<T> StructuralPartialEq for Interval<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Interval<T>where T: RefUnwindSafe,

§

impl<T> Send for Interval<T>where T: Send,

§

impl<T> Sync for Interval<T>where T: Sync,

§

impl<T> Unpin for Interval<T>where T: Unpin,

§

impl<T> UnwindSafe for Interval<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,