Enum zot::Ot [−][src]
Variants
Implementations
impl<T> Ot<T>
[src]
#[must_use =
"if you intended to assert that this has two values, consider `.unwrap_one()` instead"]pub const fn is_one(&self) -> bool
[src]
Returns true
if the option is a [One
] value.
Examples
let x: zot::Ot<u32> = zot::Ot::One(2); assert_eq!(x.is_one(), true); let x: zot::Ot<u32> = zot::Ot::Two(2, 3); assert_eq!(x.is_one(), false);
#[must_use =
"if you intended to assert that this has two values, consider `.unwrap_two()` instead"]pub const fn is_two(&self) -> bool
[src]
Returns true
if the option is a [Two
] value.
Examples
let x: zot::Ot<u32> = zot::Ot::One(2); assert_eq!(x.is_two(), false); let x: zot::Ot<u32> = zot::Ot::Two(2, 3); assert_eq!(x.is_two(), true);
#[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::Ot<u32> = zot::Ot::One(2); assert_eq!(x.contains(&2), true); let x: zot::Ot<u32> = zot::Ot::One(3); assert_eq!(x.contains(&2), false); let x: zot::Ot<u32> = zot::Ot::Two(3, 2); assert_eq!(x.contains(&2), true);
pub const fn as_ref(&self) -> Ot<&T>
[src]
Converts from &Ot<T>
to Ot<&T>
.
pub fn as_mut(&mut self) -> Ot<&mut T>
[src]
Converts from &mut Option<T>
to Option<&mut T>
.
pub fn as_pin_ref(self: Pin<&Self>) -> Ot<Pin<&T>>
[src]
Converts from [Pin
]<&Ot<T>>
to Ot<
[Pin
]<&T>>
.
pub fn as_pin_mut(self: Pin<&mut Self>) -> Ot<Pin<&mut T>>
[src]
Converts from [Pin
]<&mut Ot<T>>
to Ot<
[Pin
]<&mut T>>
.
pub fn expect_one(self, msg: &str) -> T
[src]
Returns the contained [One
] value, consuming the self
value.
Panics
Panics if the value is a [Two
] with a custom panic message provided by
msg
.
Examples
let x = zot::Ot::One("value"); assert_eq!(x.expect_one("fruits are healthy"), "value");
let x: zot::Ot<&str> = zot::Ot::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
] value as a (T, T)
, consuming the self
value.
Panics
Panics if the value is a [One
] with a custom panic message provided by
msg
.
Examples
let x = zot::Ot::Two("value", "value"); assert_eq!(x.expect_two("fruits are healthy"), ("value", "value"));
let x: zot::Ot<&str> = zot::Ot::One("value"); x.expect_two("fruits are healthy"); // panics with `fruits are healthy`
pub fn unwrap_one(self) -> T
[src]
Returns the contained [One
] value, consuming the self
value.
Panics
Panics if the self value equals [Two
].
Examples
let x = zot::Ot::One("air"); assert_eq!(x.unwrap_one(), "air");
let x: zot::Ot<&str> = zot::Ot::Two("air", "air"); 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.
Panics
Panics if the self value equals [One
].
Examples
let x = zot::Ot::Two("air", "air"); assert_eq!(x.unwrap_two(), ("air", "air"));
let x: zot::Ot<&str> = zot::Ot::One("air"); assert_eq!(x.unwrap_two(), ("air", "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::Ot::One("car").unwrap_one_or("bike"), "car"); assert_eq!(zot::Ot::Two("car", "train").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::Ot::Two("car", "train").unwrap_two_or(("bike", "pogo")), ("car", "train")); assert_eq!(zot::Ot::One("car").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::Ot::One(4).unwrap_one_or_else(|| 2 * k), 4); assert_eq!(zot::Ot::Two(4, 5).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 as a (T, T)
or computes it from a closure.
Examples
let k = 10; assert_eq!(zot::Ot::Two(4, 5).unwrap_two_or_else(|| (2 * k, 3 * k)), (4, 5)); assert_eq!(zot::Ot::One(4).unwrap_two_or_else(|| (2 * k, 3 * k)), (20, 30));
pub fn ok_one_or_else<E, F: FnOnce(T, T) -> E>(self, f: F) -> Result<T, E>
[src]
Returns a Result
with the contained [One
] value or computes an Err from a closure.
pub fn ok_two_or_else<E, F: FnOnce(T) -> E>(self, f: F) -> Result<(T, T), E>
[src]
Returns a Result
with the contained [Two
] value as a (T, T)
or computes an Err from a closure.
pub fn first(&self) -> &T
[src]
pub fn first_mut(&mut self) -> &mut T
[src]
pub fn second(&self) -> Option<&T>
[src]
pub fn second_mut(&mut self) -> Option<&mut T>
[src]
pub fn last(&self) -> &T
[src]
pub fn last_mut(&mut self) -> &mut T
[src]
pub fn map<U, F: FnMut(T) -> U>(self, f: F) -> Ot<U>
[src]
Maps an Ot<T>
to Ot<U>
by applying a function to a contained value.
Examples
Converts an Ot<
String
>
into an Ot<
usize
>
, consuming the original:
let ot_string = zot::Ot::Two(String::from("Hello, World!"), String::from("Goodbye, World!")); // `Ot::map` takes self *by value*, consuming `ot_string` let ot_len = ot_string.map(|s| s.len()); assert_eq!(ot_len, zot::Ot::Two(13, 15));
pub const fn iter(&self) -> Iter<'_, T>
[src]
Returns an iterator over the contained values.
Examples
let x = zot::Ot::Two(4, 5); let mut iter = x.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), Some(&5)); let x = zot::Ot::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::Ot::One(4); match x.iter_mut().next() { Some(v) => *v = 42, None => {}, } assert_eq!(x, zot::Ot::One(42));
pub fn replace_one(&mut self, value: T) -> Ot<T>
[src]
Replaces the actual value in the Ot
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::Ot::One(2); let old = x.replace_one(5); assert_eq!(x, zot::Ot::One(5)); assert_eq!(old, zot::Ot::One(2)); let mut x = zot::Ot::Two(5, 6); let old = x.replace_one(3); assert_eq!(x, zot::Ot::One(3)); assert_eq!(old, zot::Ot::Two(5, 6));
pub fn replace_two(&mut self, first: T, second: T) -> Ot<T>
[src]
Replaces the actual value in the Ot
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::Ot::One(2); let old = x.replace_two(5, 6); assert_eq!(x, zot::Ot::Two(5, 6)); assert_eq!(old, zot::Ot::One(2)); let mut x = zot::Ot::Two(5, 6); let old = x.replace_two(3, 4); assert_eq!(x, zot::Ot::Two(3, 4)); assert_eq!(old, zot::Ot::Two(5, 6));
pub fn replace_first(&mut self, value: T) -> T
[src]
Replaces the first value in the Ot
by the value given in parameter,
returning the old value.
Examples
let mut x = zot::Ot::Two(2, 3); let old = x.replace_first(5); assert_eq!(x, zot::Ot::Two(5, 3)); assert_eq!(old, 2); let mut x = zot::Ot::One(2); let old = x.replace_first(3); assert_eq!(x, zot::Ot::One(3)); assert_eq!(old, 2);
pub fn replace_last(&mut self, value: T) -> T
[src]
Replaces the last value in the Ot
by the value given in parameter,
returning the old value.
Examples
let mut x = zot::Ot::Two(2, 3); let old = x.replace_last(5); assert_eq!(x, zot::Ot::Two(2, 5)); assert_eq!(old, 3); let mut x = zot::Ot::One(2); let old = x.replace_last(3); assert_eq!(x, zot::Ot::One(3)); assert_eq!(old, 2);
pub fn len(&self) -> usize
[src]
Returns the number of contained elements.
Examples
let x: zot::Ot<u32> = zot::Ot::Two(7, 20); assert_eq!(x.len(), 2);
impl<T: Copy> Ot<&T>
[src]
pub fn copied(self) -> Ot<T>
[src]
Maps an Ot<&T>
to an Ot<T>
by copying the contents of the
ot.
Examples
let x = 12; let ot_x = zot::Ot::One(&x); assert_eq!(ot_x, zot::Ot::One(&12)); let copied = ot_x.copied(); assert_eq!(copied, zot::Ot::One(12));
impl<T: Copy> Ot<&mut T>
[src]
pub fn copied(self) -> Ot<T>
[src]
Maps an Ot<&mut T>
to an Ot<T>
by copying the contents of the
ot.
Examples
let mut x = 12; let ot_x = zot::Ot::One(&mut x); assert_eq!(ot_x, zot::Ot::One(&mut 12)); let copied = ot_x.copied(); assert_eq!(copied, zot::Ot::One(12));
impl<T: Clone> Ot<&T>
[src]
pub fn cloned(self) -> Ot<T>
[src]
Maps an Ot<&T>
to an Ot<T>
by cloning the contents of the
ot.
Examples
let x = 12; let ot_x = zot::Ot::One(&x); assert_eq!(ot_x, zot::Ot::One(&12)); let cloned = ot_x.cloned(); assert_eq!(cloned, zot::Ot::One(12));
impl<T: Clone> Ot<&mut T>
[src]
pub fn cloned(self) -> Ot<T>
[src]
Maps an Ot<&mut T>
to an Ot<T>
by cloning the contents of the
ot.
Examples
let mut x = 12; let ot_x = zot::Ot::One(&mut x); assert_eq!(ot_x, zot::Ot::One(&mut 12)); let cloned = ot_x.cloned(); assert_eq!(cloned, zot::Ot::One(12));
impl<T: Deref> Ot<T>
[src]
pub fn as_deref(&self) -> Ot<&T::Target>
[src]
Converts from Ot<T>
(or &Ot<T>
) to Ot<&T::Target>
.
Leaves the original Ot in-place, creating a new one with a reference
to the original one, additionally coercing the contents via [Deref
].
Examples
let x: zot::Ot<String> = zot::Ot::One("hey".to_owned()); assert_eq!(x.as_deref(), zot::Ot::One("hey"));
Trait Implementations
impl<T: Clone> Clone for Ot<T>
[src]
impl<T: Copy> Copy for Ot<T>
[src]
impl<T: Debug> Debug for Ot<T>
[src]
impl<T: Eq> Eq for Ot<T>
[src]
impl<'a, T> From<&'a Ot<T>> for Ot<&'a T>
[src]
fn from(o: &'a Ot<T>) -> Ot<&'a T>
[src]
Converts from &Ot<T>
to Ot<&T>
.
Examples
let s: zot::Ot<String> = zot::Ot::One(String::from("Hello, Rustaceans!")); let o: zot::Ot<usize> = zot::Ot::from(&s).map(|ss: &String| ss.len()); println!("Can still print s: {:?}", s); assert_eq!(o, zot::Ot::One(18));
impl<'a, T> From<&'a mut Ot<T>> for Ot<&'a mut T>
[src]
fn from(o: &'a mut Ot<T>) -> Ot<&'a mut T>
[src]
Converts from &mut Ot<T>
to Ot<&mut T>
Examples
let mut s = zot::Ot::One(String::from("Hello")); let o: zot::Ot<&mut String> = zot::Ot::from(&mut s); match o { zot::Ot::One(t) => *t = String::from("Hello, Rustaceans!"), _ => (), } assert_eq!(s, zot::Ot::One(String::from("Hello, Rustaceans!")));
impl<T> From<(T, Option<T>)> for Ot<T>
[src]
fn from(ts: (T, Option<T>)) -> Self
[src]
Create an Ot
from an element and an Option
. Returns an Ot::One
if the Option
was None
, otherwise Ot::Two
.
Examples
let x = zot::Ot::from((5, Some(2))); assert_eq!(x, zot::Ot::Two(5, 2)); let x = zot::Ot::from((5, None)); assert_eq!(x, zot::Ot::One(5));
impl<T> From<(T, T)> for Ot<T>
[src]
impl<T> From<Ot<T>> for Zot<T>
[src]
impl<T> From<T> for Ot<T>
[src]
impl<T: Hash> Hash for Ot<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 Ot<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::Ot::Two("string", "text"); let v: Vec<&str> = x.into_iter().collect(); assert_eq!(v, ["string", "text"]); let x = zot::Ot::One("string"); let v: Vec<&str> = x.into_iter().collect(); assert_eq!(v, ["string"]);
impl<'a, T> IntoIterator for &'a Ot<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 Ot<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 Ot<T>
[src]
fn cmp(&self, other: &Ot<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<Ot<T>> for Ot<T>
[src]
impl<T: PartialOrd> PartialOrd<Ot<T>> for Ot<T>
[src]
fn partial_cmp(&self, other: &Ot<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 Ot<T>
[src]
impl<T> StructuralPartialEq for Ot<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Ot<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Ot<T> where
T: Send,
T: Send,
impl<T> Sync for Ot<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Ot<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Ot<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>,