Enum bones_asset::Maybe
source · #[repr(C, u8)]pub enum Maybe<T> {
Unset,
Set(T),
}Expand description
Variants§
Implementations§
source§impl<T> Maybe<T>
impl<T> Maybe<T>
sourcepub fn contains<U>(&self, x: &U) -> boolwhere
U: PartialEq<T>,
pub fn contains<U>(&self, x: &U) -> boolwhere
U: PartialEq<T>,
Returns true if the option is a Set value containing the given value.
sourcepub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
Returns the contained Set value or computes it from a closure.
sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Maybe<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Maybe<U>
Maps a Maybe<T> to Maybe<U> by applying a function to a contained value.
sourcepub fn and_then<U, F: FnOnce(T) -> Maybe<U>>(self, f: F) -> Maybe<U>
pub fn and_then<U, F: FnOnce(T) -> Maybe<U>>(self, f: F) -> Maybe<U>
Returns Unset if the option is Unset, otherwise calls f with the wrapped value and returns the result.
sourcepub fn and<U>(self, optb: Maybe<U>) -> Maybe<U>
pub fn and<U>(self, optb: Maybe<U>) -> Maybe<U>
Returns Unset if the option is Unset, otherwise returns optb.
sourcepub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Maybe<T>
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Maybe<T>
Returns Unset if the option is Unset, otherwise calls predicate with the wrapped value and returns:
sourcepub fn or(self, optb: Maybe<T>) -> Maybe<T>
pub fn or(self, optb: Maybe<T>) -> Maybe<T>
Returns the option if it contains a value, otherwise returns optb.
sourcepub fn or_else<F: FnOnce() -> Maybe<T>>(self, f: F) -> Maybe<T>
pub fn or_else<F: FnOnce() -> Maybe<T>>(self, f: F) -> Maybe<T>
Returns the option if it contains a value, otherwise calls f and returns the result.
sourcepub fn xor(self, optb: Maybe<T>) -> Maybe<T>
pub fn xor(self, optb: Maybe<T>) -> Maybe<T>
Returns Set if exactly one of self, optb is Set, otherwise returns Unset.
sourcepub fn get_or_insert(&mut self, v: T) -> &mut T
pub fn get_or_insert(&mut self, v: T) -> &mut T
Inserts v into the option if it is Unset, then returns a mutable reference to the contained value.
sourcepub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T
pub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T
Inserts a value computed from f into the option if it is Unset, then returns a mutable reference to the contained value.
sourcepub fn take(&mut self) -> Maybe<T>
pub fn take(&mut self) -> Maybe<T>
Takes the value out of the option, leaving an Unset in its place.
sourcepub fn replace(&mut self, value: T) -> Maybe<T>
pub fn replace(&mut self, value: T) -> Maybe<T>
Replaces the actual value in the option by the value given in parameter, returning the old value if present.
sourcepub unsafe fn unwrap_unchecked(self) -> T
pub unsafe fn unwrap_unchecked(self) -> T
Returns the contained Set value, consuming the self value, without checking that the value is not Unset.
§Safety
Calling this method on an Unset value is undefined behavior.
sourcepub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U
Maps a Maybe<T> to U by applying a function to a contained value, or returns a default.
sourcepub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(
self,
default: D,
f: F,
) -> U
pub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>( self, default: D, f: F, ) -> U
Maps a Maybe<T> to U by applying a function to a contained value, or computes a default.
sourcepub fn unwrap_or_default(self) -> Twhere
T: Default,
pub fn unwrap_or_default(self) -> Twhere
T: Default,
Returns the contained Set value or a default.
sourcepub fn ok_or<E>(self, err: E) -> Result<T, E>
pub fn ok_or<E>(self, err: E) -> Result<T, E>
Transforms the Maybe<T> into a Result<T, E>, mapping Set(v) to Ok(v) and Unset to Err(err).
sourcepub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E>
pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E>
Transforms the Maybe<T> into a Result<T, E>, mapping Set(v) to Ok(v) and Unset to Err(err()).
Trait Implementations§
source§impl<T: HasSchema + Clone> HasSchema for Maybe<T>
impl<T: HasSchema + Clone> HasSchema for Maybe<T>
§fn register_schema()
fn register_schema()
§fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
§fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
§fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
§fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where
T: HasSchema,
fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where
T: HasSchema,
§fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
T to a SchemaRef§fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
T to a SchemaRefMutsource§impl<T: Ord> Ord for Maybe<T>
impl<T: Ord> Ord for Maybe<T>
source§impl<T: PartialEq> PartialEq for Maybe<T>
impl<T: PartialEq> PartialEq for Maybe<T>
source§impl<T: PartialOrd> PartialOrd for Maybe<T>
impl<T: PartialOrd> PartialOrd for Maybe<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl<T: Copy> Copy for Maybe<T>
impl<T: Eq> Eq for Maybe<T>
impl<T> StructuralPartialEq for Maybe<T>
Auto Trait Implementations§
impl<T> Freeze for Maybe<T>where
T: Freeze,
impl<T> RefUnwindSafe for Maybe<T>where
T: RefUnwindSafe,
impl<T> Send for Maybe<T>where
T: Send,
impl<T> Sync for Maybe<T>where
T: Sync,
impl<T> Unpin for Maybe<T>where
T: Unpin,
impl<T> UnwindSafe for Maybe<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.