Enum Bound

Source
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>

Source

pub fn is_finite(&self) -> bool

Returns true if the bound is an Include or Exclude value.

§Example
let x: Bound<i32> = Bound::Include(15);
assert_eq!(x.is_finite(), true);

let x: Bound<i32> = Bound::Infinite;
assert_eq!(x.is_finite(), false);
Source

pub fn is_inclusive(&self) -> bool

Returns true if the bound is an Include value.

§Example
let x: Bound<i32> = Bound::Include(15);
assert_eq!(x.is_inclusive(), true);

let x: Bound<i32> = Bound::Exclude(15);
assert_eq!(x.is_inclusive(), false);
Source

pub fn is_exclusive(&self) -> bool

Returns true if the bound is an Exclude value.

§Example
let x: Bound<i32> = Bound::Exclude(15);
assert_eq!(x.is_exclusive(), true);

let x: Bound<i32> = Bound::Include(15);
assert_eq!(x.is_exclusive(), false);
Source

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

Returns a reference to the contained point, or None if the bound is Infinite.

§Example
let x: Bound<i32> = Bound::Exclude(34);

assert_eq!(x.as_ref(), Some(&34));
Source

pub fn as_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the contained point, or None if the bound is Infinite.

§Example
let mut x: Bound<i32> = Bound::Exclude(34);

assert_eq!(x.as_mut(), Some(&mut 34));
Source

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
Source

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);
Source

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);
Source

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));
Source

pub fn map_or<U, F>(self, def: U, f: F) -> U
where F: FnOnce(T) -> U,

Applyies a function to a contained value (if finite) or returns a default value (if Infinite).

§Example
assert_eq!(Bound::Include(10).map_or(6, |k| k * 2), 20);
Source

pub fn map_or_else<U, D, F>(self, def: D, f: F) -> U
where D: FnOnce() -> U, F: FnOnce(T) -> U,

Applyies a function to a contained value (if finite) or returns a computed value (if Infinite).

§Example
assert_eq!(Bound::Include(10).map_or_else(|| 6, |k| k * 2), 20);
assert_eq!(Bound::Infinite.map_or_else(|| 6, |k: u32| k * 2), 6);
Source

pub fn transfer<B: Borrow<Self>, O>(from: B, to: O) -> Bound<O>

Constructs a new Bound by applyting the bound type to the given value.

§Example
let x: Bound<i32> = Bound::transfer(Bound::Exclude(34), 18);

assert_eq!(x, Bound::Exclude(18));
Source§

impl<T> Bound<T>
where T: PartialOrd + Clone,

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Clone> Clone for Bound<T>

Source§

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

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 Bound<T>

Source§

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

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

impl<T> Default for Bound<T>
where T: Default,

Source§

fn default() -> Self

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

impl<T> From<T> for Bound<T>

Source§

fn from(t: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Bound<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 for Bound<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy> Copy for Bound<T>

Source§

impl<T: Eq> Eq for Bound<T>

Source§

impl<T> StructuralPartialEq for Bound<T>

Auto Trait Implementations§

§

impl<T> Freeze for Bound<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.