Optional

Struct Optional 

Source
pub struct Optional<T> { /* private fields */ }

Implementations§

Source§

impl<T> Optional<T>

Source

pub fn wrap(value: Option<T>) -> Optional<T>

Source

pub fn unwrap(self) -> Option<T>

Methods from Deref<Target = Option<T>>§

1.0.0 · Source

pub fn is_some(&self) -> bool

Returns true if the option is a Some value.

§Examples
let x: Option<u32> = Some(2);
assert_eq!(x.is_some(), true);

let x: Option<u32> = None;
assert_eq!(x.is_some(), false);
1.0.0 · Source

pub fn is_none(&self) -> bool

Returns true if the option is a None value.

§Examples
let x: Option<u32> = Some(2);
assert_eq!(x.is_none(), false);

let x: Option<u32> = None;
assert_eq!(x.is_none(), true);
1.0.0 · Source

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

Converts from &Option<T> to Option<&T>.

§Examples

Calculates the length of an Option<String> as an Option<usize> without moving the String. The map method takes the self argument by value, consuming the original, so this technique uses as_ref to first take an Option to a reference to the value inside the original.

let text: Option<String> = Some("Hello, world!".to_string());
// First, cast `Option<String>` to `Option<&String>` with `as_ref`,
// then consume *that* with `map`, leaving `text` on the stack.
let text_length: Option<usize> = text.as_ref().map(|s| s.len());
println!("still can print text: {text:?}");
1.0.0 · Source

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

Converts from &mut Option<T> to Option<&mut T>.

§Examples
let mut x = Some(2);
match x.as_mut() {
    Some(v) => *v = 42,
    None => {},
}
assert_eq!(x, Some(42));
1.33.0 · Source

pub fn as_pin_ref(self: Pin<&Option<T>>) -> Option<Pin<&T>>

Converts from Pin<&Option<T>> to Option<Pin<&T>>.

1.33.0 · Source

pub fn as_pin_mut(self: Pin<&mut Option<T>>) -> Option<Pin<&mut T>>

Converts from Pin<&mut Option<T>> to Option<Pin<&mut T>>.

1.75.0 · Source

pub fn as_slice(&self) -> &[T]

Returns a slice of the contained value, if any. If this is None, an empty slice is returned. This can be useful to have a single type of iterator over an Option or slice.

Note: Should you have an Option<&T> and wish to get a slice of T, you can unpack it via opt.map_or(&[], std::slice::from_ref).

§Examples
assert_eq!(
    [Some(1234).as_slice(), None.as_slice()],
    [&[1234][..], &[][..]],
);

The inverse of this function is (discounting borrowing) [_]::first:

for i in [Some(1234_u16), None] {
    assert_eq!(i.as_ref(), i.as_slice().first());
}
1.75.0 · Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is None, an empty slice is returned. This can be useful to have a single type of iterator over an Option or slice.

Note: Should you have an Option<&mut T> instead of a &mut Option<T>, which this method takes, you can obtain a mutable slice via opt.map_or(&mut [], std::slice::from_mut).

§Examples
assert_eq!(
    [Some(1234).as_mut_slice(), None.as_mut_slice()],
    [&mut [1234][..], &mut [][..]],
);

The result is a mutable slice of zero or one items that points into our original Option:

let mut x = Some(1234);
x.as_mut_slice()[0] += 1;
assert_eq!(x, Some(1235));

The inverse of this method (discounting borrowing) is [_]::first_mut:

assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
1.40.0 · Source

pub fn as_deref(&self) -> Option<&<T as Deref>::Target>
where T: Deref,

Converts from Option<T> (or &Option<T>) to Option<&T::Target>.

Leaves the original Option in-place, creating a new one with a reference to the original one, additionally coercing the contents via Deref.

§Examples
let x: Option<String> = Some("hey".to_owned());
assert_eq!(x.as_deref(), Some("hey"));

let x: Option<String> = None;
assert_eq!(x.as_deref(), None);
1.40.0 · Source

pub fn as_deref_mut(&mut self) -> Option<&mut <T as Deref>::Target>
where T: DerefMut,

Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.

Leaves the original Option in-place, creating a new one containing a mutable reference to the inner type’s Deref::Target type.

§Examples
let mut x: Option<String> = Some("hey".to_owned());
assert_eq!(x.as_deref_mut().map(|x| {
    x.make_ascii_uppercase();
    x
}), Some("HEY".to_owned().as_mut_str()));
1.0.0 · Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

§Examples
let x = Some(4);
assert_eq!(x.iter().next(), Some(&4));

let x: Option<u32> = None;
assert_eq!(x.iter().next(), None);
1.0.0 · Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

§Examples
let mut x = Some(4);
match x.iter_mut().next() {
    Some(v) => *v = 42,
    None => {},
}
assert_eq!(x, Some(42));

let mut x: Option<u32> = None;
assert_eq!(x.iter_mut().next(), None);
1.53.0 · Source

pub fn insert(&mut self, value: T) -> &mut T

Inserts value into the option, then returns a mutable reference to it.

If the option already contains a value, the old value is dropped.

See also Option::get_or_insert, which doesn’t update the value if the option already contains Some.

§Example
let mut opt = None;
let val = opt.insert(1);
assert_eq!(*val, 1);
assert_eq!(opt.unwrap(), 1);
let val = opt.insert(2);
assert_eq!(*val, 2);
*val = 3;
assert_eq!(opt.unwrap(), 3);
1.20.0 · Source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Inserts value into the option if it is None, then returns a mutable reference to the contained value.

See also Option::insert, which updates the value even if the option already contains Some.

§Examples
let mut x = None;

{
    let y: &mut u32 = x.get_or_insert(5);
    assert_eq!(y, &5);

    *y = 7;
}

assert_eq!(x, Some(7));
1.83.0 · Source

pub fn get_or_insert_default(&mut self) -> &mut T
where T: Default,

Inserts the default value into the option if it is None, then returns a mutable reference to the contained value.

§Examples
let mut x = None;

{
    let y: &mut u32 = x.get_or_insert_default();
    assert_eq!(y, &0);

    *y = 7;
}

assert_eq!(x, Some(7));
1.20.0 · Source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where F: FnOnce() -> T,

Inserts a value computed from f into the option if it is None, then returns a mutable reference to the contained value.

§Examples
let mut x = None;

{
    let y: &mut u32 = x.get_or_insert_with(|| 5);
    assert_eq!(y, &5);

    *y = 7;
}

assert_eq!(x, Some(7));
1.0.0 · Source

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

Takes the value out of the option, leaving a None in its place.

§Examples
let mut x = Some(2);
let y = x.take();
assert_eq!(x, None);
assert_eq!(y, Some(2));

let mut x: Option<u32> = None;
let y = x.take();
assert_eq!(x, None);
assert_eq!(y, None);
1.80.0 · Source

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where P: FnOnce(&mut T) -> bool,

Takes the value out of the option, but only if the predicate evaluates to true on a mutable reference to the value.

In other words, replaces self with None if the predicate returns true. This method operates similar to Option::take but conditional.

§Examples
let mut x = Some(42);

let prev = x.take_if(|v| if *v == 42 {
    *v += 1;
    false
} else {
    false
});
assert_eq!(x, Some(43));
assert_eq!(prev, None);

let prev = x.take_if(|v| *v == 43);
assert_eq!(x, None);
assert_eq!(prev, Some(43));
1.31.0 · Source

pub fn replace(&mut self, value: T) -> Option<T>

Replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving a Some in its place without deinitializing either one.

§Examples
let mut x = Some(2);
let old = x.replace(5);
assert_eq!(x, Some(5));
assert_eq!(old, Some(2));

let mut x = None;
let old = x.replace(3);
assert_eq!(x, Some(3));
assert_eq!(old, None);

Trait Implementations§

Source§

impl<T, U, R> Add<Optional<U>> for Optional<T>
where T: Add<U, Output = R>,

Source§

type Output = Optional<R>

The resulting type after applying the + operator.
Source§

fn add(self, other: Optional<U>) -> <Optional<T> as Add<Optional<U>>>::Output

Performs the + operation. Read more
Source§

impl<T, U, R> Add<U> for Optional<T>
where T: Add<U, Output = R>, U: GroundType,

Source§

type Output = Optional<R>

The resulting type after applying the + operator.
Source§

fn add(self, other: U) -> <Optional<T> as Add<U>>::Output

Performs the + operation. Read more
Source§

impl<T> Cardinality for Optional<T>

Source§

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

Source§

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

Returns a duplicate 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> Collection for Optional<T>

Source§

type Item = T

Source§

impl<T> Contains for Optional<T>
where T: Eq,

Source§

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

Source§

impl<T> Debug for Optional<T>
where T: Debug,

Source§

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

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

impl<T> Deref for Optional<T>

Source§

type Target = Option<T>

The resulting type after dereferencing.
Source§

fn deref<'a>(&'a self) -> &'a Option<T>

Dereferences the value.
Source§

impl<T> DerefMut for Optional<T>

Source§

fn deref_mut<'a>(&'a mut self) -> &'a mut Option<T>

Mutably dereferences the value.
Source§

impl Difference<Interval<i16>> for Optional<i16>

Source§

fn difference(&self, other: &Interval<i16>) -> Optional<i16>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<i16>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<i16>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<i16>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i16>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<i16>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i16>

Source§

impl Difference<Interval<i32>> for Optional<i32>

Source§

fn difference(&self, other: &Interval<i32>) -> Optional<i32>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<i32>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<i32>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<i32>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i32>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<i32>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i32>

Source§

impl Difference<Interval<i64>> for Optional<i64>

Source§

fn difference(&self, other: &Interval<i64>) -> Optional<i64>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<i64>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<i64>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<i64>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i64>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<i64>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i64>

Source§

impl Difference<Interval<i8>> for Optional<i8>

Source§

fn difference(&self, other: &Interval<i8>) -> Optional<i8>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<i8>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<i8>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<i8>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i8>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<i8>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i8>

Source§

impl Difference<Interval<isize>> for Optional<isize>

Source§

fn difference(&self, other: &Interval<isize>) -> Optional<isize>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<isize>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<isize>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<isize>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<isize>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<isize>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<isize>

Source§

impl Difference<Interval<u16>> for Optional<u16>

Source§

fn difference(&self, other: &Interval<u16>) -> Optional<u16>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<u16>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<u16>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<u16>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u16>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<u16>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u16>

Source§

impl Difference<Interval<u32>> for Optional<u32>

Source§

fn difference(&self, other: &Interval<u32>) -> Optional<u32>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<u32>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<u32>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<u32>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u32>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<u32>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u32>

Source§

impl Difference<Interval<u64>> for Optional<u64>

Source§

fn difference(&self, other: &Interval<u64>) -> Optional<u64>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<u64>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<u64>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<u64>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u64>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<u64>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u64>

Source§

impl Difference<Interval<u8>> for Optional<u8>

Source§

fn difference(&self, other: &Interval<u8>) -> Optional<u8>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<u8>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<u8>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<u8>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u8>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<u8>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u8>

Source§

impl Difference<Interval<usize>> for Optional<usize>

Source§

fn difference(&self, other: &Interval<usize>) -> Optional<usize>

Calculates whether an optional is outside of an interval.

assert_eq!(Optional::<usize>::singleton(4).difference(&Interval::new(3, 8)), Optional::empty());
assert_eq!(Optional::<usize>::singleton(8).difference(&Interval::new(7, 9)), Optional::empty());
assert_eq!(Optional::<usize>::singleton(3).difference(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<usize>::singleton(9).difference(&Interval::empty()), Optional::singleton(9));
assert_eq!(Optional::<usize>::empty().difference(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<usize>

Source§

impl<Bound> Difference<Optional<Bound>> for Interval<Bound>
where Bound: Ord + Num + Clone,

Source§

fn difference(&self, value: &Optional<Bound>) -> Interval<Bound>

Calculates the interval covering values in the left interval, excluding value. See Difference<Bound> for details of when the Optional contains a value.

assert_eq!(Interval::new(4, 9).difference(&Optional::singleton(5)), Interval::new(4, 9));
assert_eq!(Interval::new(3, 5).difference(&Optional::empty()), Interval::new(3, 5));
assert_eq!(Interval::new(8, 8).difference(&Optional::empty()), Interval::new(8, 8));
Source§

type Output = Interval<Bound>

Source§

impl Difference<Optional<bool>> for bool

Source§

impl Difference<Optional<char>> for char

Source§

impl Difference<Optional<f32>> for f32

Source§

impl Difference<Optional<f64>> for f64

Source§

impl Difference<Optional<i16>> for i16

Source§

impl Difference<Optional<i32>> for i32

Source§

impl Difference<Optional<i64>> for i64

Source§

impl Difference<Optional<i8>> for i8

Source§

impl Difference<Optional<isize>> for isize

Source§

impl Difference<Optional<u16>> for u16

Source§

impl Difference<Optional<u32>> for u32

Source§

impl Difference<Optional<u64>> for u64

Source§

impl Difference<Optional<u8>> for u8

Source§

impl Difference<Optional<usize>> for usize

Source§

impl<T> Difference<T> for Optional<T>
where T: Clone + PartialEq,

Source§

type Output = Optional<T>

Source§

fn difference(&self, other: &T) -> <Optional<T> as Difference<T>>::Output

Source§

impl<T> Difference for Optional<T>
where T: Clone + PartialEq,

Source§

type Output = Optional<T>

Source§

fn difference(&self, other: &Optional<T>) -> <Optional<T> as Difference>::Output

Source§

impl Disjoint<Interval<i16>> for Optional<i16>

Source§

fn is_disjoint(&self, value: &Interval<i16>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<i16>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<i16>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<i16>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<i16>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<i16>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<i16>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<i16>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<i32>> for Optional<i32>

Source§

fn is_disjoint(&self, value: &Interval<i32>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<i32>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<i32>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<i32>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<i32>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<i32>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<i32>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<i32>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<i64>> for Optional<i64>

Source§

fn is_disjoint(&self, value: &Interval<i64>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<i64>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<i64>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<i64>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<i64>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<i64>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<i64>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<i64>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<i8>> for Optional<i8>

Source§

fn is_disjoint(&self, value: &Interval<i8>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<i8>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<i8>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<i8>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<i8>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<i8>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<i8>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<i8>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<isize>> for Optional<isize>

Source§

fn is_disjoint(&self, value: &Interval<isize>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<isize>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<isize>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<isize>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<isize>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<isize>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<isize>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<isize>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<u16>> for Optional<u16>

Source§

fn is_disjoint(&self, value: &Interval<u16>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<u16>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<u16>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<u16>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<u16>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<u16>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<u16>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<u16>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<u32>> for Optional<u32>

Source§

fn is_disjoint(&self, value: &Interval<u32>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<u32>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<u32>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<u32>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<u32>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<u32>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<u32>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<u32>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<u64>> for Optional<u64>

Source§

fn is_disjoint(&self, value: &Interval<u64>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<u64>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<u64>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<u64>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<u64>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<u64>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<u64>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<u64>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<u8>> for Optional<u8>

Source§

fn is_disjoint(&self, value: &Interval<u8>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<u8>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<u8>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<u8>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<u8>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<u8>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<u8>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<u8>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl Disjoint<Interval<usize>> for Optional<usize>

Source§

fn is_disjoint(&self, value: &Interval<usize>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Optional::<usize>::singleton(1).is_disjoint(&Interval::new(8, 9)), true);
assert_eq!(Optional::<usize>::singleton(3).is_disjoint(&Interval::new(1, 5)), false);
assert_eq!(Optional::<usize>::singleton(5).is_disjoint(&Interval::new(3, 5)), false);
assert_eq!(Optional::<usize>::singleton(3).is_disjoint(&Interval::new(3, 3)), false);
assert_eq!(Optional::<usize>::singleton(6).is_disjoint(&Interval::empty()), true);
assert_eq!(Optional::<usize>::empty().is_disjoint(&Interval::new(4, 7)), true);
assert_eq!(Optional::<usize>::empty().is_disjoint(&Interval::empty()), true);
Source§

impl<Bound> Disjoint<Optional<Bound>> for Interval<Bound>
where Bound: Num + Ord,

Source§

fn is_disjoint(&self, value: &Optional<Bound>) -> bool

Calculates whether an optional is excluded from an interval.

assert_eq!(Interval::new(8, 9).is_disjoint(&Optional::singleton(1)), true);
assert_eq!(Interval::new(1, 5).is_disjoint(&Optional::singleton(3)), false);
assert_eq!(Interval::new(3, 5).is_disjoint(&Optional::singleton(5)), false);
assert_eq!(Interval::new(3, 3).is_disjoint(&Optional::singleton(3)), false);
assert_eq!(Interval::<usize>::empty().is_disjoint(&Optional::singleton(6)), true);
assert_eq!(Interval::new(4, 7).is_disjoint(&Optional::empty()), true);
assert_eq!(Interval::<isize>::empty().is_disjoint(&Optional::empty()), true);
Source§

impl<T> Disjoint<Optional<T>> for bool
where T: Disjoint<bool>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for char
where T: Disjoint<char>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for f32
where T: Disjoint<f32>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for f64
where T: Disjoint<f64>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for i16
where T: Disjoint<i16>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for i32
where T: Disjoint<i32>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for i64
where T: Disjoint<i64>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for i8
where T: Disjoint<i8>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for isize
where T: Disjoint<isize>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for u16
where T: Disjoint<u16>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for u32
where T: Disjoint<u32>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for u64
where T: Disjoint<u64>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for u8
where T: Disjoint<u8>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T> Disjoint<Optional<T>> for usize
where T: Disjoint<usize>,

Source§

fn is_disjoint(&self, other: &Optional<T>) -> bool

Source§

impl<T, U> Disjoint<Optional<U>> for Optional<T>
where T: Disjoint<U>,

Source§

fn is_disjoint(&self, other: &Optional<U>) -> bool

Source§

impl<T, U> Disjoint<U> for Optional<T>
where T: Disjoint<U>, U: GroundType,

Source§

fn is_disjoint(&self, other: &U) -> bool

Source§

impl<T> Empty for Optional<T>

Source§

impl Intersection<Interval<i16>> for Optional<i16>

Source§

fn intersection(&self, other: &Interval<i16>) -> Optional<i16>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<i16>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<i16>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<i16>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i16>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<i16>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i16>

Source§

impl Intersection<Interval<i32>> for Optional<i32>

Source§

fn intersection(&self, other: &Interval<i32>) -> Optional<i32>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<i32>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<i32>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<i32>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i32>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<i32>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i32>

Source§

impl Intersection<Interval<i64>> for Optional<i64>

Source§

fn intersection(&self, other: &Interval<i64>) -> Optional<i64>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<i64>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<i64>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<i64>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i64>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<i64>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i64>

Source§

impl Intersection<Interval<i8>> for Optional<i8>

Source§

fn intersection(&self, other: &Interval<i8>) -> Optional<i8>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<i8>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<i8>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<i8>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<i8>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<i8>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<i8>

Source§

impl Intersection<Interval<isize>> for Optional<isize>

Source§

fn intersection(&self, other: &Interval<isize>) -> Optional<isize>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<isize>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<isize>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<isize>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<isize>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<isize>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<isize>

Source§

impl Intersection<Interval<u16>> for Optional<u16>

Source§

fn intersection(&self, other: &Interval<u16>) -> Optional<u16>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<u16>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<u16>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<u16>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u16>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<u16>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u16>

Source§

impl Intersection<Interval<u32>> for Optional<u32>

Source§

fn intersection(&self, other: &Interval<u32>) -> Optional<u32>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<u32>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<u32>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<u32>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u32>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<u32>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u32>

Source§

impl Intersection<Interval<u64>> for Optional<u64>

Source§

fn intersection(&self, other: &Interval<u64>) -> Optional<u64>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<u64>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<u64>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<u64>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u64>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<u64>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u64>

Source§

impl Intersection<Interval<u8>> for Optional<u8>

Source§

fn intersection(&self, other: &Interval<u8>) -> Optional<u8>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<u8>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<u8>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<u8>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<u8>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<u8>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<u8>

Source§

impl Intersection<Interval<usize>> for Optional<usize>

Source§

fn intersection(&self, other: &Interval<usize>) -> Optional<usize>

Calculates whether the optional is contained in an interval.

assert_eq!(Optional::<usize>::singleton(4).intersection(&Interval::new(3, 8)), Optional::singleton(4));
assert_eq!(Optional::<usize>::singleton(9).intersection(&Interval::new(7, 9)), Optional::singleton(9));
assert_eq!(Optional::<usize>::singleton(0).intersection(&Interval::new(1, 4)), Optional::empty());
assert_eq!(Optional::<usize>::singleton(9).intersection(&Interval::empty()), Optional::empty());
assert_eq!(Optional::<usize>::empty().intersection(&Interval::new(2, 6)), Optional::empty());
Source§

type Output = Optional<usize>

Source§

impl<Bound> Intersection<Optional<Bound>> for Interval<Bound>
where Bound: Width + Num,

Source§

fn intersection(&self, value: &Optional<Bound>) -> Interval<Bound>

Calculates whether an optional is contained in an interval. Returns the optional if it is in the interval.

assert_eq!(Interval::new(3, 8).intersection(&Optional::singleton(4)), Interval::singleton(4));
assert_eq!(Interval::new(7, 9).intersection(&Optional::singleton(9)), Interval::singleton(9));
assert_eq!(Interval::new(1, 4).intersection(&Optional::singleton(0)), Interval::empty());
assert_eq!(Interval::empty().intersection(&Optional::singleton(9)), Interval::empty());
assert_eq!(Interval::new(2, 6).intersection(&Optional::empty()), Interval::empty());
Source§

type Output = Interval<Bound>

Source§

impl Intersection<Optional<bool>> for bool

Source§

impl Intersection<Optional<char>> for char

Source§

impl Intersection<Optional<f32>> for f32

Source§

impl Intersection<Optional<f64>> for f64

Source§

impl Intersection<Optional<i16>> for i16

Source§

impl Intersection<Optional<i32>> for i32

Source§

impl Intersection<Optional<i64>> for i64

Source§

impl Intersection<Optional<i8>> for i8

Source§

impl Intersection<Optional<isize>> for isize

Source§

impl Intersection<Optional<u16>> for u16

Source§

impl Intersection<Optional<u32>> for u32

Source§

impl Intersection<Optional<u64>> for u64

Source§

impl Intersection<Optional<u8>> for u8

Source§

impl Intersection<Optional<usize>> for usize

Source§

impl<T> Intersection<T> for Optional<T>
where T: Clone + PartialEq,

Source§

type Output = Optional<T>

Source§

fn intersection(&self, other: &T) -> <Optional<T> as Intersection<T>>::Output

Source§

impl<T> Intersection for Optional<T>
where T: Clone + PartialEq,

Source§

type Output = Optional<T>

Source§

fn intersection( &self, other: &Optional<T>, ) -> <Optional<T> as Intersection>::Output

Source§

impl<T, U, R> Mul<Optional<U>> for Optional<T>
where T: Mul<U, Output = R>,

Source§

type Output = Optional<R>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Optional<U>) -> <Optional<T> as Mul<Optional<U>>>::Output

Performs the * operation. Read more
Source§

impl<T, U, R> Mul<U> for Optional<T>
where T: Mul<U, Output = R>, U: GroundType,

Source§

type Output = Optional<R>

The resulting type after applying the * operator.
Source§

fn mul(self, other: U) -> <Optional<T> as Mul<U>>::Output

Performs the * operation. Read more
Source§

impl<T> Ord for Optional<T>
where T: Ord,

Source§

fn cmp(&self, other: &Optional<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl Overlap<Interval<i16>> for Optional<i16>

Source§

fn overlap(&self, other: &Interval<i16>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<i16>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<i16>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<i16>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<i16>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<i16>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<i16>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<i16>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<i32>> for Optional<i32>

Source§

fn overlap(&self, other: &Interval<i32>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<i32>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<i32>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<i32>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<i32>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<i32>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<i32>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<i32>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<i64>> for Optional<i64>

Source§

fn overlap(&self, other: &Interval<i64>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<i64>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<i64>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<i64>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<i64>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<i64>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<i64>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<i64>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<i8>> for Optional<i8>

Source§

fn overlap(&self, other: &Interval<i8>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<i8>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<i8>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<i8>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<i8>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<i8>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<i8>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<i8>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<isize>> for Optional<isize>

Source§

fn overlap(&self, other: &Interval<isize>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<isize>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<isize>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<isize>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<isize>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<isize>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<isize>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<isize>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<u16>> for Optional<u16>

Source§

fn overlap(&self, other: &Interval<u16>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<u16>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<u16>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<u16>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<u16>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<u16>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<u16>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<u16>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<u32>> for Optional<u32>

Source§

fn overlap(&self, other: &Interval<u32>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<u32>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<u32>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<u32>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<u32>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<u32>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<u32>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<u32>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<u64>> for Optional<u64>

Source§

fn overlap(&self, other: &Interval<u64>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<u64>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<u64>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<u64>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<u64>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<u64>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<u64>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<u64>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<u8>> for Optional<u8>

Source§

fn overlap(&self, other: &Interval<u8>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<u8>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<u8>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<u8>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<u8>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<u8>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<u8>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<u8>::empty().overlap(&Interval::empty()), false);
Source§

impl Overlap<Interval<usize>> for Optional<usize>

Source§

fn overlap(&self, other: &Interval<usize>) -> bool

Calculates whether an optional is included in an interval.

assert_eq!(Optional::<usize>::singleton(1).overlap(&Interval::new(8, 9)), false);
assert_eq!(Optional::<usize>::singleton(3).overlap(&Interval::new(1, 5)), true);
assert_eq!(Optional::<usize>::singleton(5).overlap(&Interval::new(3, 5)), true);
assert_eq!(Optional::<usize>::singleton(3).overlap(&Interval::new(3, 3)), true);
assert_eq!(Optional::<usize>::singleton(6).overlap(&Interval::empty()), false);
assert_eq!(Optional::<usize>::empty().overlap(&Interval::new(4, 7)), false);
assert_eq!(Optional::<usize>::empty().overlap(&Interval::empty()), false);
Source§

impl<Bound> Overlap<Optional<Bound>> for Interval<Bound>
where Bound: Width + Num,

Source§

fn overlap(&self, other: &Optional<Bound>) -> bool

Calculates whether an optional is included from an interval.

assert_eq!(Interval::new(8, 9).overlap(&Optional::singleton(1)), false);
assert_eq!(Interval::new(1, 5).overlap(&Optional::singleton(3)), true);
assert_eq!(Interval::new(3, 5).overlap(&Optional::singleton(5)), true);
assert_eq!(Interval::new(3, 3).overlap(&Optional::singleton(3)), true);
assert_eq!(Interval::<usize>::empty().overlap(&Optional::singleton(6)), false);
assert_eq!(Interval::new(4, 7).overlap(&Optional::empty()), false);
assert_eq!(Interval::<isize>::empty().overlap(&Optional::empty()), false);
Source§

impl<Bound: Width + Num> Overlap<Optional<Bound>> for IntervalSet<Bound>

Source§

fn overlap(&self, value: &Optional<Bound>) -> bool

Calculates whether an optional value is included in the interval set. If the optional empty, this returns false. This returns the same result as the IntervalSet::contains

let interval_set = [(3, 5), (8, 9)].to_interval_set();
assert!(interval_set.overlap(&Optional::singleton(3)));
assert!(interval_set.overlap(&Optional::singleton(9)));

assert!(!interval_set.overlap(&Optional::singleton(1)));
assert!(!interval_set.overlap(&Optional::singleton(10)));

assert!(!interval_set.overlap(&Optional::empty()));
Source§

impl<T> Overlap<Optional<T>> for bool
where T: Overlap<bool>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for char
where T: Overlap<char>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for f32
where T: Overlap<f32>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for f64
where T: Overlap<f64>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for i16
where T: Overlap<i16>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for i32
where T: Overlap<i32>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for i64
where T: Overlap<i64>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for i8
where T: Overlap<i8>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for isize
where T: Overlap<isize>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for u16
where T: Overlap<u16>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for u32
where T: Overlap<u32>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for u64
where T: Overlap<u64>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for u8
where T: Overlap<u8>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T> Overlap<Optional<T>> for usize
where T: Overlap<usize>,

Source§

fn overlap(&self, other: &Optional<T>) -> bool

Source§

impl<T, U> Overlap<Optional<U>> for Optional<T>
where T: Overlap<U>,

Source§

fn overlap(&self, other: &Optional<U>) -> bool

Source§

impl<T, U> Overlap<U> for Optional<T>
where T: Overlap<U>, U: GroundType,

Source§

fn overlap(&self, other: &U) -> bool

Source§

impl<T> PartialEq for Optional<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Optional<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> PartialOrd for Optional<T>
where T: PartialOrd,

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> ProperSubset for Optional<T>
where T: Subset + PartialEq,

Source§

fn is_proper_subset(&self, other: &Optional<T>) -> bool

Source§

impl<T> Singleton for Optional<T>

Source§

fn singleton(value: T) -> Optional<T>

Source§

impl<T, U, R> Sub<Optional<U>> for Optional<T>
where T: Sub<U, Output = R>,

Source§

type Output = Optional<R>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Optional<U>) -> <Optional<T> as Sub<Optional<U>>>::Output

Performs the - operation. Read more
Source§

impl<T, U, R> Sub<U> for Optional<T>
where T: Sub<U, Output = R>, U: GroundType,

Source§

type Output = Optional<R>

The resulting type after applying the - operator.
Source§

fn sub(self, other: U) -> <Optional<T> as Sub<U>>::Output

Performs the - operation. Read more
Source§

impl<T> Subset for Optional<T>
where T: Subset,

Source§

fn is_subset(&self, other: &Optional<T>) -> bool

Source§

impl<T> Copy for Optional<T>
where T: Copy,

Source§

impl<T> Eq for Optional<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Optional<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Optional<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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<R> IsEmpty for R
where R: Cardinality,

Source§

fn is_empty(&self) -> bool

Source§

impl<R> IsSingleton for R
where R: Cardinality,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.