pub enum Finalizable<T> {
Working(T),
Finalized(T),
}
Expand description
A value that can be a working value or a finalized value.
All operations on a single Finalizable<T>
do not modify a finalized value.
Variants§
Implementations§
Source§impl<T> Finalizable<T>
impl<T> Finalizable<T>
Sourcepub fn new(value: T, finalized: bool) -> Self
pub fn new(value: T, finalized: bool) -> Self
Create a new finalizable value from a value and a boolean that determines if it is a finalized or working value.
Sourcepub fn get_as_ref(&self) -> &T
pub fn get_as_ref(&self) -> &T
Get the value from a reference to a finalizable value, whether working or finalized, as a reference to the underlying value.
Sourcepub fn try_get_mut(&mut self) -> Option<&mut T>
pub fn try_get_mut(&mut self) -> Option<&mut T>
Get the value from a mutable reference to a working value
as a mutable reference. Returns None
if the value is a finalized value.
Sourcepub fn set(self, value: T) -> Self
pub fn set(self, value: T) -> Self
Override a working value. Does nothing to a finalized value.
Sourcepub fn is_working(&self) -> bool
pub fn is_working(&self) -> bool
Check if a value is a working value.
Sourcepub fn is_finalized(&self) -> bool
pub fn is_finalized(&self) -> bool
Check if a value is a finalized value.
Sourcepub fn working_or_none(self) -> Option<T>
pub fn working_or_none(self) -> Option<T>
Get the value, but only if it is a working value.
Returns None
if the value is a finalized value.
Sourcepub fn finalized_or_none(self) -> Option<T>
pub fn finalized_or_none(self) -> Option<T>
Get the value, but only if it is a finalized value.
Returns None
if the value is a working value.
Sourcepub fn finalized_or(self, default: T) -> T
pub fn finalized_or(self, default: T) -> T
Get the value, but only if it is a finalized value.
Returns default
if the value is a working value.
Sourcepub fn finalized_or_else<F: FnOnce(T) -> T>(self, op: F) -> T
pub fn finalized_or_else<F: FnOnce(T) -> T>(self, op: F) -> T
Get the value, but only if it is a finalized value.
Calls default
and returns its result if the value is a working value.
Sourcepub fn as_ref(&self) -> Finalizable<&T>
pub fn as_ref(&self) -> Finalizable<&T>
Turn a reference to a finalizable value into a finalizable reference.
Sourcepub fn map<F: FnOnce(T) -> T>(self, op: F) -> Self
pub fn map<F: FnOnce(T) -> T>(self, op: F) -> Self
Apply a function to a working value. Does nothing to a finalized value.
Sourcepub fn map_and_finalize<F: FnOnce(T) -> T>(self, op: F) -> Self
pub fn map_and_finalize<F: FnOnce(T) -> T>(self, op: F) -> Self
Apply a function to a working value and finalize it. Does nothing to a finalized value.
Sourcepub fn expect_finalized(self, msg: &str) -> T
pub fn expect_finalized(self, msg: &str) -> T
Get a finalized value, panicking with msg
if the value is a working value.
Sourcepub fn and(self, fin: Self) -> Self
pub fn and(self, fin: Self) -> Self
Return fin
if the value is a working value, returning a finalized value unchanged.
Sourcepub fn and_then<F: FnOnce(T) -> Self>(self, op: F) -> Self
pub fn and_then<F: FnOnce(T) -> Self>(self, op: F) -> Self
Call op
on the value if it is a working value,
returning a finalized value unchanged.
Sourcepub fn and_then_new<F: FnOnce(T) -> (T, bool)>(self, op: F) -> Self
pub fn and_then_new<F: FnOnce(T) -> (T, bool)>(self, op: F) -> Self
Call op
on the value if it is a working value,
creating a new finalizable value by using the returned tuple
as the arguments to new
, returning a finalized value unchanged.
Source§impl<T> Finalizable<&T>
impl<T> Finalizable<&T>
Sourcepub fn copied(self) -> Finalizable<T>where
T: Copy,
pub fn copied(self) -> Finalizable<T>where
T: Copy,
Make a copy of a finalizable value by copying the underlying value.
Sourcepub fn cloned(self) -> Finalizable<T>where
T: Clone,
pub fn cloned(self) -> Finalizable<T>where
T: Clone,
Make a clone of a finalizable value by cloning the underlying value.
Trait Implementations§
Source§impl<T: Clone> Clone for Finalizable<T>
impl<T: Clone> Clone for Finalizable<T>
Source§fn clone(&self) -> Finalizable<T>
fn clone(&self) -> Finalizable<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more