pub enum Bound<T> {
Include(T),
Exclude(T),
Infinite,
}
Expand description
Determines the type of an Interval
’s boundary point.
Variants§
Include(T)
The bound includes the point.
Exclude(T)
The bound excludes the point.
Infinite
The bound does not exist.
Implementations§
Source§impl<T> Bound<T>
impl<T> Bound<T>
Sourcepub fn is_inclusive(&self) -> bool
pub fn is_inclusive(&self) -> bool
Sourcepub fn is_exclusive(&self) -> bool
pub fn is_exclusive(&self) -> bool
Sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Moves the value out of the Bound<T>
if it is Include
or
Exclude
.
In general, because this function may panic, its use is discouraged.
Instead, prefer to use pattern matching and handle the Infinite
case explicitly.
§Panics
Panics if the self value equals Infinite
.
§Examples
let x: Bound<i32> = Bound::Exclude(34);
assert_eq!(x.unwrap(), 34);
let x: Bound<i32> = Bound::Infinite;
assert_eq!(x.unwrap(), 34); // fails
Sourcepub fn unwrap_or(self, def: T) -> T
pub fn unwrap_or(self, def: T) -> T
Returns the bound value or a default.
§Example
assert_eq!(Bound::Exclude(34).unwrap_or(15), 34);
assert_eq!(Bound::Infinite.unwrap_or(15), 15);
Sourcepub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
Returns the bound value or computes it from a closure.
§Example
let k = 10;
assert_eq!(Bound::Exclude(34).unwrap_or_else(|| 2 * k), 34);
assert_eq!(Bound::Infinite.unwrap_or_else(|| 2 * k), 20);
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U>
Maps an Bound<T>
to Bound<U>
by applying a function to a contained
value.
§Example
let x: Bound<u32> = Bound::Include(10);
let y: Bound<usize> = x.map(|v| v as usize);
assert_eq!(y, Bound::Include(10usize));
Sourcepub fn map_or_else<U, D, F>(self, def: D, f: F) -> U
pub fn map_or_else<U, D, F>(self, def: D, f: F) -> U
Source§impl<T> Bound<T>where
T: PartialOrd + Clone,
impl<T> Bound<T>where
T: PartialOrd + Clone,
Sourcepub fn least_union(&self, other: &Self) -> Self
pub fn least_union(&self, other: &Self) -> Self
Returns the union of the given boundaries, or the lowest one if they are not at the same point.
Sourcepub fn least_intersect(&self, other: &Self) -> Self
pub fn least_intersect(&self, other: &Self) -> Self
Returns the intersect of the given boundaries, or the lowest one if they are not at the same point.
Sourcepub fn greatest_union(&self, other: &Self) -> Self
pub fn greatest_union(&self, other: &Self) -> Self
Returns the union of the given boundaries, or the greatest one if they are not at the same point.
Sourcepub fn greatest_intersect(&self, other: &Self) -> Self
pub fn greatest_intersect(&self, other: &Self) -> Self
Returns the intersect of the given boundaries, or the greatest one if they are not at the same point.