Skip to main content

TrackedState

Struct TrackedState 

Source
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>
where T: Debug + Clone + PartialEq + Default,

Provides methods to guarantee that states are updated once and only once per time step

Source

pub fn new(value: T) -> Self

Source

pub fn inner(&self) -> &T

Returns a reference to the inner value without freshness checking. Intended for use with #[serde(serialize_with)] helpers.

Source

pub fn mark_stale(&mut self)

Reset the tracked state to [State::Stale] for the next update after verifying that is has been updated

Source

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 value
  • loc: closure that returns file and line number where called
Source

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 value
  • loc: closure that returns file and line number where called
Source

pub fn get_fresh<F: Fn() -> String>(&self, loc: F) -> Result<&T>

Check that value has been updated and then return as a result

§Arguments
  • loc: call site location filename and line number
Source

pub fn get_stale<F: Fn() -> String>(&self, loc: F) -> Result<&T>

Check that value has not been updated and then return as a result

§Arguments
  • loc: call site location filename and line number
Source§

impl<T: Debug + Clone + PartialEq + Default + AddAssign> TrackedState<T>

State methods that allow for +=

Source

pub fn increment<F: Fn() -> String>(&mut self, value: T, loc: F) -> Result<()>

Update the value of the tracked state

§Arguments
  • value: new value
  • loc: closure that returns file and line number where called

Trait Implementations§

Source§

impl<T: Clone> Clone for TrackedState<T>

Source§

fn clone(&self) -> TrackedState<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for TrackedState<T>

Source§

impl<T: Debug> Debug for TrackedState<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for TrackedState<T>

Source§

fn default() -> TrackedState<T>

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Deserialize<'de> for TrackedState<T>

Source§

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: Display> Display for TrackedState<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for TrackedState<T>

Source§

fn eq(&self, other: &TrackedState<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T> Serialize for TrackedState<T>
where T: Debug + Clone + PartialEq + for<'de> Deserialize<'de> + Serialize + Default,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for TrackedState<T>

Source§

impl<T> TrackedStateMethods for TrackedState<T>
where T: Debug + Clone + PartialEq + Default,

Source§

fn mark_fresh<F: Fn() -> String>(&mut self, loc: F) -> Result<()>

Verify that state is [State::Stale] and mark state as [State::Fresh] without updating

§Arguments
  • loc: closure that returns file and line number where called
Source§

fn check_and_reset<F: Fn() -> String>(&mut self, loc: F) -> Result<()>

Ensure [State::Fresh] and reset to [State::Stale] Read more

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> UnsafeUnpin for TrackedState<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for TrackedState<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> EqDefault for T
where T: Default + PartialEq,

Source§

fn eq_default(&self) -> bool

If self is default, returns true
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.