pub struct TrackedState<T>(/* private fields */);Expand description
Struct for storing state variable and ensuring one mutation per initialization or reset – i.e. one mutation per time step
Implementations§
Source§impl<T> TrackedState<T>
Provides methods to guarantee that states are updated once and only once per time step
impl<T> TrackedState<T>
Provides methods to guarantee that states are updated once and only once per time step
pub fn new(value: T) -> Self
Sourcepub fn mark_stale(&mut self)
pub fn mark_stale(&mut self)
Reset the tracked state to [State::Stale] for the next update after verifying that is has been updated
Sourcepub fn update<F: Fn() -> String>(&mut self, value: T, loc: F) -> Result<()>
pub fn update<F: Fn() -> String>(&mut self, value: T, loc: F) -> Result<()>
Update the value of the tracked state after verifying that it has not already been updated
§Arguments
value: new valueloc: closure that returns file and line number where called
Sourcepub fn update_unchecked<F: Fn() -> String>(
&mut self,
value: T,
_loc: F,
) -> Result<()>
pub fn update_unchecked<F: Fn() -> String>( &mut self, value: T, _loc: F, ) -> Result<()>
Update the value of the tracked state without verifying that it has not already been updated – to be used sparingly!
§Arguments
value: new valueloc: closure that returns file and line number where called
Trait Implementations§
Source§impl<T: Clone> Clone for TrackedState<T>
impl<T: Clone> Clone for TrackedState<T>
Source§fn clone(&self) -> TrackedState<T>
fn clone(&self) -> TrackedState<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for TrackedState<T>
impl<T: Debug> Debug for TrackedState<T>
Source§impl<T: Default> Default for TrackedState<T>
impl<T: Default> Default for TrackedState<T>
Source§fn default() -> TrackedState<T>
fn default() -> TrackedState<T>
Returns the “default value” for a type. Read more
Source§impl<'de, T> Deserialize<'de> for TrackedState<T>
impl<'de, T> Deserialize<'de> for TrackedState<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: PartialEq> PartialEq for TrackedState<T>
impl<T: PartialEq> PartialEq for TrackedState<T>
Source§impl<T> Serialize for TrackedState<T>
impl<T> Serialize for TrackedState<T>
Source§impl<T> TrackedStateMethods for TrackedState<T>
impl<T> TrackedStateMethods for TrackedState<T>
impl<T> StructuralPartialEq for TrackedState<T>
Auto Trait Implementations§
impl<T> Freeze for TrackedState<T>where
T: Freeze,
impl<T> RefUnwindSafe for TrackedState<T>where
T: RefUnwindSafe,
impl<T> Send for TrackedState<T>where
T: Send,
impl<T> Sync for TrackedState<T>where
T: Sync,
impl<T> Unpin for TrackedState<T>where
T: Unpin,
impl<T> UnwindSafe for TrackedState<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
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more