pub enum Quantified<T> {
None,
Some(T),
Excluding(T),
All,
}
Variants§
Implementations§
Source§impl<T> Quantified<T>
impl<T> Quantified<T>
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Quantified<U>
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));
Sourcepub const fn as_ref(&self) -> Quantified<&T>
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);
Sourcepub fn as_mut(&mut self) -> Quantified<&mut T>
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>
impl<T: Deref> Quantified<T>
Sourcepub fn as_deref(&self) -> Quantified<&T::Target>
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>
impl<T: DerefMut> Quantified<T>
Sourcepub fn as_deref_mut(&mut self) -> Quantified<&mut T::Target>
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>
impl<T: Clone> Clone for Quantified<T>
Source§fn clone(&self) -> Quantified<T>
fn clone(&self) -> Quantified<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more