[][src]Enum normalize_interval::bound::Bound

pub enum Bound<T> {
    Include(T),
    Exclude(T),
    Infinite,
}

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

impl<T> Bound<T> where
    T: PartialOrd + PartialEq + Clone
[src]

pub fn is_finite(&self) -> bool[src]

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

pub fn is_inclusive(&self) -> bool[src]

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

pub fn is_exclusive(&self) -> bool[src]

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

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

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

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

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

pub fn unwrap(self) -> T[src]

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);
This example panics
let x: Bound<i32> = Bound::Infinite;
assert_eq!(x.unwrap(), 34); // fails

pub fn unwrap_or(self, def: T) -> T[src]

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

pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T[src]

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

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U>[src]

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

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

Applyies a function to a contained value (if finite) or returns a default value (if [Infinte]).

Example

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

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

Applyies a function to a contained value (if finite) or returns a computed value (if [Infinte]).

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

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

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

Trait Implementations

impl<T: Clone> Clone for Bound<T>[src]

impl<T: Copy> Copy for Bound<T>[src]

impl<T: Debug> Debug for Bound<T>[src]

impl<T> Default for Bound<T> where
    T: Default
[src]

impl<T: Eq> Eq for Bound<T>[src]

impl<T> From<T> for Bound<T>[src]

impl<T: Hash> Hash for Bound<T>[src]

impl<T: PartialEq> PartialEq<Bound<T>> for Bound<T>[src]

impl<T> StructuralEq for Bound<T>[src]

impl<T> StructuralPartialEq for Bound<T>[src]

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.