Erm

Enum Erm 

Source
pub enum Erm<T> {
    Yes(T),
    No,
    Maybe(T),
    MaybeNot,
    DontKnow,
}
Expand description

You can use this like an Option with the first two variants, but you can do…more.

Variants§

§

Yes(T)

This is Option::Some. It works.

§

No

This is Option::None. It does not work.

§

Maybe(T)

Outputs of randomised procedures, for example, can be represented with this variant. It means you’re confident enough in the outcome that you’d like to go ahead with it, while making sure you remember that stuff could go wrong.

§

MaybeNot

This variant is for when it’s probably a good idea to treat the outcome as a failure, but if you’re really optimistic, you can still try it.

§

DontKnow

No promises. You really should retry or something.

Implementations§

Source§

impl<T> Erm<T>

Source

pub fn is(&self) -> bool

Like is_some().

Source

pub fn is_and(self, f: impl FnOnce(T) -> bool) -> bool

Like is_some_and().

Source

pub fn is_not(&self) -> bool

Like is_none().

Source

pub fn is_not_or(self, f: impl FnOnce(T) -> bool) -> bool

Like is_none_or().

Source

pub fn might_be(&self) -> bool

Optimistic.

Source

pub fn might_not_be(&self) -> bool

Pessimistic.

Source

pub fn known(&self) -> bool

Source

pub fn unknown(&self) -> bool

Source

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

Source

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

Source

pub fn expect(self, msg: &str) -> T

Source

pub fn expect_sure(self, msg: &str) -> T

Source

pub fn unwrap(self) -> T

Source

pub fn unwrap_sure(self) -> T

Source

pub fn unwrap_or(self, default: T) -> T

Source

pub fn unwrap_sure_or(self, default: T) -> T

Source

pub fn unwrap_or_else(self, f: impl FnOnce() -> T) -> T

Source

pub fn unwrap_sure_or_else(self, f: impl FnOnce() -> T) -> T

Source

pub fn unwrap_or_default(self) -> T
where T: Default,

Source

pub fn unwrap_sure_or_default(self) -> T
where T: Default,

Source

pub unsafe fn unwrap_unchecked(self) -> T

Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Erm<U>

Source

pub fn inspect(self, f: impl FnOnce(&T)) -> Erm<T>

Source

pub fn map_or<U>(self, default: U, f: impl FnOnce(T) -> U) -> U

Source

pub fn map_or_else<U>( self, default: impl FnOnce() -> U, f: impl FnOnce(T) -> U, ) -> U

Source

pub fn map_or_default<U, F>(self, f: F) -> U
where U: Default, F: FnOnce(T) -> U,

Source

pub fn ok_or(self, err: T) -> Result<T, T>

Source

pub fn sure_or(self, err: T) -> Result<T, T>

Source

pub fn ok_or_else(self, err: impl FnOnce() -> T) -> Result<T, T>

Source

pub fn sure_or_else(self, err: impl FnOnce() -> T) -> Result<T, T>

Source

pub fn as_deref(&self) -> Erm<&T::Target>
where T: Deref,

Source

pub fn as_deref_mut(&mut self) -> Erm<&mut T::Target>
where T: DerefMut,

Source

pub const fn take(&mut self) -> Erm<T>

Source

pub fn ensure(self) -> Erm<T>

Source

pub fn and<U>(self, other: Erm<U>) -> Erm<U>

Source

pub fn and_sure<U>(self, other: Erm<U>) -> Erm<U>

Source

pub fn and_then<U, F>(self, f: F) -> Erm<U>
where F: FnOnce(T) -> Erm<U>,

Source

pub fn and_then_sure<U, F>(self, f: F) -> Erm<U>
where F: FnOnce(T) -> Erm<U>,

Source

pub fn filter<P>(self, predicate: P) -> Erm<T>
where P: Fn(&T) -> bool,

Source

pub fn or(self, optb: Erm<T>) -> Erm<T>

Source

pub fn or_sure(self, optb: Erm<T>) -> Erm<T>

Source

pub fn or_else(self, f: impl FnOnce() -> Erm<T>) -> Erm<T>

Source

pub fn or_else_sure(self, f: impl FnOnce() -> Erm<T>) -> Erm<T>

Source

pub fn xor(self, other: Erm<T>) -> Erm<T>

Source

pub fn iter(&self) -> Iter<'_, T>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Source

pub fn insert(&mut self, value: T) -> &mut T

Source

pub fn insert_maybe(&mut self, value: T) -> &mut T

Source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Source

pub fn get_or_insert_maybe(&mut self, value: T) -> &mut T

Source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where F: FnOnce() -> T,

Source

pub fn get_or_insert_with_maybe<F>(&mut self, f: F) -> &mut T
where F: FnOnce() -> T,

Source

pub fn get_or_insert_default(&mut self) -> &mut T
where T: Default,

Source

pub fn take_if<P>(&mut self, predicate: P) -> Erm<T>
where P: FnOnce(&mut T) -> bool,

Source

pub const fn replace(&mut self, value: T) -> Erm<T>

Source

pub fn zip<U>(self, other: Erm<U>) -> Erm<(T, U)>

Source

pub fn zip_or_default<U>(self, other: Erm<U>) -> Erm<(T, U)>
where T: Default, U: Default,

Source

pub fn zip_with<U, F>(self, other: Erm<U>, f: F) -> Erm<T>
where F: FnOnce(T, U) -> T,

Source§

impl<T, U> Erm<(T, U)>

Source

pub fn unzip(self) -> (Erm<T>, Erm<U>)

Source§

impl<T> Erm<&T>

Source

pub fn copied(self) -> Erm<T>
where T: Copy,

Source

pub fn cloned(self) -> Erm<T>
where T: Clone,

Source§

impl<T> Erm<&mut T>

Source

pub fn copied(self) -> Erm<T>
where T: Copy,

Source

pub fn cloned(self) -> Erm<T>
where T: Clone,

Source§

impl<T, E> Erm<Result<T, E>>

Source

pub fn transpose(self) -> Result<Erm<T>, E>

Trait Implementations§

Source§

impl<T: Clone> Clone for Erm<T>

Source§

fn clone(&self) -> Erm<T>

Returns a duplicate 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 Erm<T>

Source§

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

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

impl<T> Default for Erm<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T> From<&'a Erm<T>> for Erm<&'a T>

Source§

fn from(value: &'a Erm<T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T> From<&'a mut Erm<T>> for Erm<&'a mut T>

Source§

fn from(value: &'a mut Erm<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Erm<T>

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Erm<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Erm<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Into<Option<T>> for Erm<T>

Source§

fn into(self) -> Option<T>

Converts this type into the (usually inferred) input type.
Source§

impl<'a, T> IntoIterator for &'a Erm<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut Erm<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Erm<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for Erm<T>

Source§

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

Source§

impl<T: Eq> Eq for Erm<T>

Source§

impl<T> StructuralPartialEq for Erm<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Erm<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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.