Enum zot::Zot [−][src]
A collection of exactly zero, one, or two T
elements.
Variants
No value
One value
Two values
Implementations
impl<T> Zot<T>
[src]
#[must_use]pub const fn is_zero(&self) -> bool
[src]
Returns true
if the Zot
is a [Zero
] value.
Examples
let x: zot::Zot<u32>= zot::Zot::Zero; assert_eq!(x.is_zero(), true); let x: zot::Zot<u32>= zot::Zot::Two(2, 3); assert_eq!(x.is_zero(), false);
#[must_use =
"if you intended to assert that this has a value, consider `.unwrap_one()` instead"]pub const fn is_one(&self) -> bool
[src]
Returns true
if the Zot
is a [One
] value.
Examples
let x: zot::Zot<u32>= zot::Zot::One(2); assert_eq!(x.is_one(), true); let x: zot::Zot<u32>= zot::Zot::Two(2, 3); assert_eq!(x.is_one(), false);
#[must_use =
"if you intended to assert that this has a value, consider `.unwrap_two()` instead"]pub const fn is_two(&self) -> bool
[src]
Returns true
if the Zot
is a [Two
] value.
Examples
let x: zot::Zot<u32>= zot::Zot::Two(2, 3); assert_eq!(x.is_two(), true); let x: zot::Zot<u32>= zot::Zot::One(2); assert_eq!(x.is_two(), false);
#[must_use]pub fn contains<U>(&self, v: &U) -> bool where
U: PartialEq<T>,
[src]
U: PartialEq<T>,
Returns true
if at least one contained value equals the given value.
Examples
let x: zot::Zot<u32>= zot::Zot::One(2); assert_eq!(x.contains(&2), true); let x: zot::Zot<u32>= zot::Zot::One(3); assert_eq!(x.contains(&2), false); let x: zot::Zot<u32>= zot::Zot::Two(3, 2); assert_eq!(x.contains(&2), true); let x: zot::Zot<u32>= zot::Zot::Zero; assert_eq!(x.contains(&2), false);
pub const fn as_ref(&self) -> Zot<&T>
[src]
Converts from &Zot<T>
to Zot<&T>
.
pub fn as_mut(&mut self) -> Zot<&mut T>
[src]
Converts from &mut Zot<T>
to Zot<&mut T>
.
pub fn as_pin_ref(self: Pin<&Self>) -> Zot<Pin<&T>>
[src]
Converts from [Pin
]<&Zot<T>>
to Zot<
[Pin
]<&T>>
.
pub fn as_pin_mut(self: Pin<&mut Self>) -> Zot<Pin<&mut T>>
[src]
Converts from [Pin
]<&mut Zot<T>>
to Zot<
[Pin
]<&mut T>>
.
pub fn expect_zero(self, msg: &str)
[src]
Returns the contained [Zero
] value, consuming the self
value.
Panics
Panics if the value is not [Zero
] with a custom panic message provided by
msg
.
Examples
let x: zot::Zot<&str>= zot::Zot::Zero; assert_eq!(x.expect_zero("fruits are healthy"), ());
let x= zot::Zot::One("value"); x.expect_zero("fruits are healthy"); // panics with `fruits are healthy`
pub fn expect_one(self, msg: &str) -> T
[src]
Returns the contained [One
] value, consuming the self
value.
Panics
Panics if the value is not [One
] with a custom panic message provided by
msg
.
Examples
let x= zot::Zot::One("value"); assert_eq!(x.expect_one("fruits are healthy"), "value");
let x= zot::Zot::Two("value", "value"); x.expect_one("fruits are healthy"); // panics with `fruits are healthy`
pub fn expect_two(self, msg: &str) -> (T, T)
[src]
Returns the contained [Two
] values as a (T, T)
, consuming the self
value.
Panics
Panics if the value is not [Two
] with a custom panic message provided by
msg
.
Examples
let x= zot::Zot::Two("value", "value"); assert_eq!(x.expect_two("fruits are healthy"), ("value", "value"));
let x= zot::Zot::One("value"); x.expect_two("fruits are healthy"); // panics with `fruits are healthy`
pub fn expect_option(self, msg: &str) -> Option<T>
[src]
Returns the contained [Zero
] or [One
] value as an Option<T>
, consuming the self
value.
Panics
Panics if the value is [Two
] with a custom panic message provided by
msg
.
Examples
let x= zot::Zot::One("value"); assert_eq!(x.expect_option("fruits are healthy"), Some("value"));
let x= zot::Zot::Two("value", "value"); x.expect_option("fruits are healthy"); // panics with `fruits are healthy`
pub fn unwrap_zero(self)
[src]
Returns the contained [Zero
] value, consuming the self
value.
Because this function may panic, its use is generally discouraged.
Instead, prefer to use pattern matching and handle the [Zero
]
case explicitly, or call unwrap_zero_or
, unwrap_zero_or_else
.
Panics
Panics if the self value is not [Zero
].
Examples
let x: zot::Zot<&str>= zot::Zot::Zero; assert_eq!(x.unwrap_zero(), ());
let x= zot::Zot::One("air"); assert_eq!(x.unwrap_zero(), ()); // fails
pub fn unwrap_one(self) -> T
[src]
Returns the contained [One
] value, consuming the self
value.
Because this function may panic, its use is generally discouraged.
Instead, prefer to use pattern matching and handle the [One
]
case explicitly, or call unwrap_one_or
, unwrap_one_or_else
.
Panics
Panics if the self value is not [One
].
Examples
let x= zot::Zot::One("air"); assert_eq!(x.unwrap_one(), "air");
let x= zot::Zot::Two("air", "wind"); assert_eq!(x.unwrap_one(), "air"); // fails
pub fn unwrap_two(self) -> (T, T)
[src]
Returns the contained [Two
] value as a (T, T)
, consuming the self
value.
Because this function may panic, its use is generally discouraged.
Instead, prefer to use pattern matching and handle the [Two
]
case explicitly, or call unwrap_two_or
, unwrap_two_or_else
.
Panics
Panics if the self value is not [Two
].
Examples
let x= zot::Zot::Two("air", "wind"); assert_eq!(x.unwrap_two(), ("air", "wind"));
let x= zot::Zot::One("air"); assert_eq!(x.unwrap_two(), ("air", "wind")); // fails
pub fn unwrap_option(self) -> Option<T>
[src]
Returns the contained [Zero
] or [One
] value as an Option<T>
, consuming the self
value.
Because this function may panic, its use is generally discouraged.
Instead, prefer to use pattern matching and handle the [Zero
]
and [One'] cases explicitly, or call [
unwrap_option_or], [
unwrap_option_or_else`].
Panics
Panics if the self value is not [Zero
] or [One
].
Examples
let x= zot::Zot::One("air"); assert_eq!(x.unwrap_option(), Some("air"));
let x= zot::Zot::Two("air", "wind"); assert_eq!(x.unwrap_option(), Some("air")); // fails
pub fn unwrap_one_or(self, default: T) -> T
[src]
Returns the contained [One
] value or a provided default.
Arguments passed to unwrap_one_or
are eagerly evaluated; if you are passing
the result of a function call, it is recommended to use unwrap_one_or_else
,
which is lazily evaluated.
Examples
assert_eq!(zot::Zot::One("car").unwrap_one_or("bike"), "car"); assert_eq!(zot::Zot::Zero.unwrap_one_or("bike"), "bike");
pub fn unwrap_two_or(self, default: (T, T)) -> (T, T)
[src]
Returns the contained [Two
] value as a (T, T)
or a provided default.
Arguments passed to unwrap_two_or
are eagerly evaluated; if you are passing
the result of a function call, it is recommended to use unwrap_two_or_else
,
which is lazily evaluated.
Examples
assert_eq!(zot::Zot::Two("car", "truck").unwrap_two_or(("bike", "pogo")), ("car", "truck")); assert_eq!(zot::Zot::Zero.unwrap_two_or(("bike", "pogo")), ("bike", "pogo"));
pub fn unwrap_one_or_else<F: FnOnce() -> T>(self, f: F) -> T
[src]
Returns the contained [One
] value or computes it from a closure.
Examples
let k = 10; assert_eq!(zot::Zot::One(4).unwrap_one_or_else(|| 2 * k), 4); assert_eq!(zot::Zot::Zero.unwrap_one_or_else(|| 2 * k), 20);
pub fn unwrap_two_or_else<F: FnOnce() -> (T, T)>(self, f: F) -> (T, T)
[src]
Returns the contained [Two
] value or computes it from a closure.
Examples
let k = 10; assert_eq!(zot::Zot::Two(4, 5).unwrap_two_or_else(|| (2 * k, 3 * k)), (4, 5)); assert_eq!(zot::Zot::Zero.unwrap_two_or_else(|| (2 * k, 3 * k)), (20, 30));
pub fn first(&self) -> Option<&T>
[src]
pub fn first_mut(&mut self) -> Option<&mut T>
[src]
pub fn second(&self) -> Option<&T>
[src]
pub fn second_mut(&mut self) -> Option<&mut T>
[src]
pub fn last(&self) -> Option<&T>
[src]
pub fn last_mut(&mut self) -> Option<&mut T>
[src]
pub fn map<U, F: FnMut(T) -> U>(self, f: F) -> Zot<U>
[src]
Maps a Zot<T>
to Zot<U>
by applying a function to a contained values.
pub const fn iter(&self) -> Iter<'_, T>
[src]
Returns an iterator over the contained values.
Examples
let x= zot::Zot::Two(4, 5); let mut iter = x.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), Some(&5)); let x= zot::Zot::One(4); let mut iter = x.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), None);
pub fn iter_mut(&mut self) -> IterMut<'_, T>
[src]
Returns a mutable iterator over the contained values.
Examples
let mut x= zot::Zot::One(4); match x.iter_mut().next() { Some(v) => *v = 42, None => {}, } assert_eq!(x, zot::Zot::One(42)); let mut x: zot::Zot<u32>= zot::Zot::Zero; assert_eq!(x.iter_mut().next(), None);
pub fn take(&mut self) -> Zot<T>
[src]
Takes the value out of the Zot
, leaving a [Zero
] in its place.
Examples
let mut x = zot::Zot::One(2); let y = x.take(); assert_eq!(x, zot::Zot::Zero); assert_eq!(y, zot::Zot::One(2)); let mut x: zot::Zot<u32> = zot::Zot::Zero; let y = x.take(); assert_eq!(x, zot::Zot::Zero); assert_eq!(y, zot::Zot::Zero);
pub fn take_first(&mut self) -> Option<T>
[src]
Takes the first value out of the Zot
, leaving only [One
] if
there were initially two values, otherwise [Zero
].
Examples
let mut x = zot::Zot::Two(2, 3); let y = x.take_first(); assert_eq!(x, zot::Zot::One(3)); assert_eq!(y, Some(2)); let mut x: zot::Zot<u32> = zot::Zot::Zero; let y = x.take_first(); assert_eq!(x, zot::Zot::Zero); assert_eq!(y, None);
pub fn take_second(&mut self) -> Option<T>
[src]
Takes the second value out of the Zot
if it is [Two
], leaving
only [One
], otherwise the Zot
is unchanged.
Examples
let mut x = zot::Zot::Two(2, 3); let y = x.take_second(); assert_eq!(x, zot::Zot::One(2)); assert_eq!(y, Some(3)); let mut x: zot::Zot<u32> = zot::Zot::One(2); let y = x.take_second(); assert_eq!(x, zot::Zot::One(2)); assert_eq!(y, None);
pub fn take_last(&mut self) -> Option<T>
[src]
Takes the last value out of the Zot
, leaving only [One
] if
there were initially two values, otherwise [Zero
].
Examples
let mut x = zot::Zot::Two(2, 3); let y = x.take_last(); assert_eq!(x, zot::Zot::One(2)); assert_eq!(y, Some(3)); let mut x: zot::Zot<u32> = zot::Zot::Zero; let y = x.take_last(); assert_eq!(x, zot::Zot::Zero); assert_eq!(y, None);
pub fn replace_one(&mut self, value: T) -> Zot<T>
[src]
Replaces the actual value in the Zot
by the value given in parameter,
returning the old value,
leaving a [One
] in its place without deinitializing either one.
Examples
let mut x = zot::Zot::One(2); let old = x.replace_one(5); assert_eq!(x, zot::Zot::One(5)); assert_eq!(old, zot::Zot::One(2)); let mut x = zot::Zot::Zero; let old = x.replace_one(3); assert_eq!(x, zot::Zot::One(3)); assert_eq!(old, zot::Zot::Zero);
pub fn replace_two(&mut self, first: T, second: T) -> Zot<T>
[src]
Replaces the actual value in the Zot
by the values given in parameter,
returning the old value,
leaving a [Two
] in its place without deinitializing either one.
Examples
let mut x = zot::Zot::One(2); let old = x.replace_two(5, 6); assert_eq!(x, zot::Zot::Two(5, 6)); assert_eq!(old, zot::Zot::One(2)); let mut x = zot::Zot::Zero; let old = x.replace_two(3, 4); assert_eq!(x, zot::Zot::Two(3, 4)); assert_eq!(old, zot::Zot::Zero);
pub fn replace_first(&mut self, value: T) -> Option<T>
[src]
Replaces the first value in the Zot
by the value given in parameter,
returning the old value if present,
leaving a [One
] or [Two
] in its place without deinitializing either one.
Examples
let mut x = zot::Zot::Two(2, 3); let old = x.replace_first(5); assert_eq!(x, zot::Zot::Two(5, 3)); assert_eq!(old, Some(2)); let mut x = zot::Zot::Zero; let old = x.replace_first(3); assert_eq!(x, zot::Zot::One(3)); assert_eq!(old, None);
pub fn replace_last(&mut self, value: T) -> Option<T>
[src]
Replaces the last value in the Zot
by the value given in parameter,
returning the old value if present,
leaving a [One
] or [Two
] in its place without deinitializing either one.
Examples
let mut x = zot::Zot::Two(2, 3); let old = x.replace_last(5); assert_eq!(x, zot::Zot::Two(2, 5)); assert_eq!(old, Some(3)); let mut x = zot::Zot::Zero; let old = x.replace_last(3); assert_eq!(x, zot::Zot::One(3)); assert_eq!(old, None);
pub fn from_options(a: Option<T>, b: Option<T>) -> Self
[src]
Construct a Zot
from two Option
s.
Examples
let x: zot::Zot<u32>= zot::Zot::from_options(None, Some(3)); assert_eq!(x, zot::Zot::One(3)); let x: zot::Zot<u32>= zot::Zot::from_options(Some(2), Some(3)); assert_eq!(x, zot::Zot::Two(2, 3));
pub fn len(&self) -> usize
[src]
Returns the number of contained elements.
Examples
let x: zot::Zot<u32>= zot::Zot::Two(7, 20); assert_eq!(x.len(), 2);
pub fn without_first(&self) -> Self where
T: Clone,
[src]
T: Clone,
pub fn without_second(&self) -> Self where
T: Clone,
[src]
T: Clone,
pub fn remove_second(self) -> Self where
T: Clone,
[src]
T: Clone,
Trait Implementations
impl<T: Clone> Clone for Zot<T>
[src]
impl<T: Copy> Copy for Zot<T>
[src]
impl<T: Debug> Debug for Zot<T>
[src]
impl<T> Default for Zot<T>
[src]
fn default() -> Self
[src]
Returns [Zero
][zot::Zot::Zero].
Examples
let z: zot::Zot<u32> = zot::Zot::default(); assert!(z.is_zero());
impl<T: Eq> Eq for Zot<T>
[src]
impl<'a, T> From<&'a Zot<T>> for Zot<&'a T>
[src]
fn from(o: &'a Zot<T>) -> Zot<&'a T>
[src]
Converts from &Zot<T>
to Zot<&T>
.
Examples
let s: zot::Zot<String> = zot::Zot::One(String::from("Hello, Rustaceans!")); let o: zot::Zot<usize> = zot::Zot::from(&s).map(|ss: &String| ss.len()); println!("Can still print s: {:?}", s); assert_eq!(o, zot::Zot::One(18));
impl<'a, T> From<&'a mut Zot<T>> for Zot<&'a mut T>
[src]
fn from(o: &'a mut Zot<T>) -> Zot<&'a mut T>
[src]
Converts from &mut Zot<T>
to Zot<&mut T>
Examples
let mut s = zot::Zot::One(String::from("Hello")); let o: zot::Zot<&mut String> = zot::Zot::from(&mut s); match o { zot::Zot::One(t) => *t = String::from("Hello, Rustaceans!"), _ => (), } assert_eq!(s, zot::Zot::One(String::from("Hello, Rustaceans!")));
impl<T> From<(Option<T>, Option<T>)> for Zot<T>
[src]
fn from(ts: (Option<T>, Option<T>)) -> Self
[src]
Creates a Zot
from two Option
s.
Examples
let x = zot::Zot::from((None, Some(2))); assert_eq!(x, zot::Zot::One(2)); let x = zot::Zot::from((Some(3), Some(4))); assert_eq!(x, zot::Zot::Two(3, 4));
impl<T> From<(Option<T>, T)> for Zot<T>
[src]
impl<T> From<(T, Option<T>)> for Zot<T>
[src]
impl<T> From<(T, T)> for Zot<T>
[src]
impl<T> From<Option<(T, Option<T>)>> for Zot<T>
[src]
impl<T> From<Option<T>> for Zot<T>
[src]
impl<T> From<Ot<T>> for Zot<T>
[src]
impl<T> From<T> for Zot<T>
[src]
impl<T: Hash> Hash for Zot<T>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> IntoIterator for Zot<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
Returns a consuming iterator any contained values.
Examples
let x = zot::Zot::Two("string", "text"); let v: Vec<&str> = x.into_iter().collect(); assert_eq!(v, ["string", "text"]); let x = zot::Zot::Zero; let v: Vec<&str> = x.into_iter().collect(); assert!(v.is_empty());
impl<'a, T> IntoIterator for &'a Zot<T>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a mut Zot<T>
[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Ord> Ord for Zot<T>
[src]
fn cmp(&self, other: &Zot<T>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<Zot<T>> for Zot<T>
[src]
impl<T: PartialOrd> PartialOrd<Zot<T>> for Zot<T>
[src]
fn partial_cmp(&self, other: &Zot<T>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> StructuralEq for Zot<T>
[src]
impl<T> StructuralPartialEq for Zot<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Zot<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Zot<T> where
T: Send,
T: Send,
impl<T> Sync for Zot<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Zot<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Zot<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[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]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,