pub struct MaybeValue<V>(/* private fields */);Expand description
A value that may or may not be present.
This is the Rust counterpart of FusionCache’s MaybeValue<T>. It is a thin,
purpose-named wrapper around Option so the public API reads the same as
FusionCache (has_value, value_or_default, from_value, …) while still
interoperating freely with idiomatic Option via From.
It appears in two places:
- the return type of
Cache::try_get— a miss isMaybeValue::none, distinct from “present butNone/null”; - the
fail_safe_defaultargument ofCache::get_or_set— a last-resort value used only when the factory fails and no stale entry exists.
Implementations§
Source§impl<V> MaybeValue<V>
impl<V> MaybeValue<V>
Sourcepub fn from_value(value: V) -> Self
pub fn from_value(value: V) -> Self
A present value.
Sourcepub fn into_value(self) -> Option<V>
pub fn into_value(self) -> Option<V>
Consumes the wrapper, returning the contained value, if any.
Sourcepub fn map<U, F: FnOnce(V) -> U>(self, f: F) -> MaybeValue<U>
pub fn map<U, F: FnOnce(V) -> U>(self, f: F) -> MaybeValue<U>
Maps the contained value, preserving absence.
Source§impl<V: Clone> MaybeValue<V>
impl<V: Clone> MaybeValue<V>
Sourcepub fn value_or_clone(&self, default: V) -> V
pub fn value_or_clone(&self, default: V) -> V
Returns a clone of the contained value or default when absent.
Source§impl<V: Default> MaybeValue<V>
impl<V: Default> MaybeValue<V>
Sourcepub fn value_or_default(self) -> V
pub fn value_or_default(self) -> V
Returns the contained value or V::default() when absent.
Trait Implementations§
Source§impl<V: Clone> Clone for MaybeValue<V>
impl<V: Clone> Clone for MaybeValue<V>
Source§fn clone(&self) -> MaybeValue<V>
fn clone(&self) -> MaybeValue<V>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<V: Debug> Debug for MaybeValue<V>
impl<V: Debug> Debug for MaybeValue<V>
Source§impl<V> Default for MaybeValue<V>
impl<V> Default for MaybeValue<V>
Source§fn default() -> Self
fn default() -> Self
The default is MaybeValue::none, matching default(MaybeValue<T>).
impl<V: Eq> Eq for MaybeValue<V>
Source§impl<V> From<MaybeValue<V>> for Option<V>
impl<V> From<MaybeValue<V>> for Option<V>
Source§fn from(maybe: MaybeValue<V>) -> Self
fn from(maybe: MaybeValue<V>) -> Self
Converts to this type from the input type.
Source§impl<V> From<Option<V>> for MaybeValue<V>
impl<V> From<Option<V>> for MaybeValue<V>
Source§impl<V> From<V> for MaybeValue<V>
impl<V> From<V> for MaybeValue<V>
Source§impl<V: PartialEq> PartialEq for MaybeValue<V>
impl<V: PartialEq> PartialEq for MaybeValue<V>
impl<V: PartialEq> StructuralPartialEq for MaybeValue<V>
Auto Trait Implementations§
impl<V> Freeze for MaybeValue<V>
impl<V> RefUnwindSafe for MaybeValue<V>where
Option<V>: RefUnwindSafe,
impl<V> Send for MaybeValue<V>
impl<V> Sync for MaybeValue<V>
impl<V> Unpin for MaybeValue<V>
impl<V> UnsafeUnpin for MaybeValue<V>where
Option<V>: UnsafeUnpin,
impl<V> UnwindSafe for MaybeValue<V>where
Option<V>: 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.