Enum Quantified

Source
pub enum Quantified<T> {
    None,
    Some(T),
    Excluding(T),
    All,
}

Variants§

§

None

§

Some(T)

§

Excluding(T)

§

All

Implementations§

Source§

impl<T> Quantified<T>

Source

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Quantified<U>

Maps an Quantified<T> to Quantified<U> by applying a function to a contained Some or Excluding value.

§Examples

Converts an Quantified<String> into an Quantified<usize>, consuming the original:

let some_string = Quantified::Some(String::from("Hello, World!"));
// `Quantified::map` takes self *by value*, consuming `maybe_some_string`
let some_len = some_string.map(|s| s.len());

assert_eq!(some_len, Quantified::Some(13));
Source

pub const fn as_ref(&self) -> Quantified<&T>

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

§Examples

Converts a Quantified<String> into a Quantified<usize>, preserving the original. The map method takes the self argument by value, consuming the original, so this technique uses as_ref to first take a Quantified to a reference to the value inside the original.

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

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

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

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

impl<T: Deref> Quantified<T>

Source

pub fn as_deref(&self) -> Quantified<&T::Target>

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

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

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

let x: Quantified<String> = Quantified::All;
assert_eq!(x.as_deref(), Quantified::All);
Source§

impl<T: DerefMut> Quantified<T>

Source

pub fn as_deref_mut(&mut self) -> Quantified<&mut T::Target>

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

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

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

Trait Implementations§

Source§

impl<T: Clone> Clone for Quantified<T>

Source§

fn clone(&self) -> Quantified<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 Quantified<T>

Source§

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

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

impl<T: Ord> Ord for Quantified<T>

Source§

fn cmp(&self, other: &Quantified<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<T: PartialEq> PartialEq for Quantified<T>

Source§

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

Source§

fn partial_cmp(&self, other: &Quantified<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: Eq> Eq for Quantified<T>

Source§

impl<T> StructuralPartialEq for Quantified<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Quantified<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<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.