[][src]Enum quantified::Quantified

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

Variants

None
Some(T)
Excluding(T)
All

Implementations

impl<T> Quantified<T>[src]

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

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

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

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

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

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

impl<T: Deref> Quantified<T>[src]

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

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

impl<T: DerefMut> Quantified<T>[src]

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

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

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

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

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

impl<T: Ord> Ord for Quantified<T>[src]

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

impl<T: PartialOrd> PartialOrd<Quantified<T>> for Quantified<T>[src]

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

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

Auto Trait Implementations

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

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