Unsure<T> Enum
Unsure<T> is a custom enum which is essentially
Option<T>
with an additional Reject variant, for handling values that are deemed to be
wholly negative (such as a failure state or an invalid input).
Implementation Details
Derived Traits
Debug: AllowsUnsure<T>values to be formatted for debugging purposes.Clone: AllowsUnsure<T>values to be explicitly cloned with.clone()Copy: AllowsUnsure<T>values to be copied implicitly, allowing duplication without.clone().PartialEq: AllowsUnsure<T>values to be compared for equality.Eq: AllowsUnsure<T>values to be compared for total equality.Hash: AllowsUnsure<T>values to be used as keys inHashMaporHashSet.PartialOrd: AllowsUnsure<T>values to be compared for partial ordering.Ord: AllowsUnsure<T>values to be compared for total ordering.
Variants
Reject: An erroneous or unwanted value, used to mark a situation where an unsure state should be rejected or cancelled. This is the main reason for usingUnsure<T>overOption<T>- if you don't need to manage failure separately from absence, just stick withOption<T>.Nothing: No value, likeOption<T>'sNone, used to mark a situation where an unsure state should be ignored or skipped. Takes its name after Haskell'sNothingvariant of theMaybetype.Just(T): Some value of typeT, likeOption<T>'sSome(T), used to confirm that an unsure state is valid and confirmed. Takes its name after Haskell'sJust avariant of theMaybetype.
Methods
is_reject(&self) -> bool: Returnstrueif the value isReject,falseotherwise.is_nothing(&self) -> bool: Returnstrueif the value isNothing,falseotherwise.is_just(&self) -> bool: Returnstrueif the value isJust(T),falseotherwise.as_ref(&self) -> Option<&T>: Returns a reference to the value asSome(&T)if it isJust(T),Noneotherwise.as_mut(&mut self) -> Option<&mut T>: Returns a mutable reference to the value asSome(&mut T)if it isJust(T),Noneotherwise.unwrap(self) -> T: Returns the value asTif it isJust(T), panics otherwise.unwrap_or(self, default: T) -> T: Returns the value asTif it isJust(T), otherwise returnsdefault.unwrap_or_else(self, f: impl FnOnce() -> T) -> T: Returns the value asTif it isJust(T), otherwise callsfand returns the result.unwrap_or_default(self) -> T: Returns the value asTif it isJust(T), returns the default if it isNothing, panics if it isReject.
From
From<Option<T>>: Converts anOption<T>to anUnsure<T>.Some(T)maps ontoJust(T),Nonemaps ontoNothing. It is impossible to obtain aRejectfrom this conversion.
Installation
unsure-rs (unsure on crates.io) is a library crate, so you must add it to
an existing Rust project:
cargo add unsure
You can additionally type it out manually in Cargo.toml, but using the CLI
is easier.
Usage
See the docs.rs for usage instructions and detailed explanations of the enum.