Skip to main content

Stamped

Struct Stamped 

Source
pub struct Stamped<T> { /* private fields */ }
Expand description

A signal wrapper that stamps every write with the time it happened, so a reader can ask how old the value is.

The read-side half of write freshness. The monitor side already exists: writes: [X observed beat] with a beat_timeout: reports a node that has not written recently. Stamped gives the consumer the same fact at the point of use — age, is_fresh, read_fresh — for the case the monitor cannot cover: a value that is still being written but must not be trusted past a certain age. What neither can tell is whether a fresh value is valid; a plausible-looking drift needs a consumer that understands the value.

Writes go through w, reads through r; there is deliberately no Deref, so an unstamped write path does not exist. It records the time and nothing else — compose Stamped<Counted<T>> when the write count matters too. Costs one AtomicU32 and one AtomicBool beside the wrapped value. The stamp is Instant ticks truncated to u32, like the node heartbeat: ages are exact up to u32::MAX ticks.

Implementations§

Source§

impl<T> Stamped<T>

Source

pub const fn new(inner: T) -> Self

Wrap inner, never written.

Source

pub fn w(&self) -> &T

Borrow the inner signal for a write, stamping now.

Source

pub fn r(&self) -> &T

Borrow the inner signal for a read.

Source

pub fn inner(&self) -> &T

Borrow the inner signal without touching the stamp.

Source

pub fn age(&self) -> Option<Duration>

Time since the last stamped write, None until the first.

Source

pub fn is_fresh(&self, max_age: Duration) -> bool

Has the signal been written within max_age?

Source

pub fn read_fresh(&self, max_age: Duration) -> Option<&T>

The inner signal if it was written within max_age, else None.

Trait Implementations§

Source§

impl<T: Observable> Observable for Stamped<T>

Available on crate feature coupling-observe only.
Source§

fn change_token(&self) -> u32

Return a token that changes when the signal is written.
Source§

impl<T: Sink> Sink for Stamped<T>

Available on crate feature dataflow only.
Source§

type Item = <T as Sink>::Item

The value type written into the signal.
Source§

fn put(&self, v: T::Item)

Write v into the signal.
Source§

impl<T: Source> Source for Stamped<T>

Available on crate feature dataflow only.
Source§

type Item = <T as Source>::Item

The value type read from the signal.
Source§

fn get(&self) -> T::Item

Return a snapshot of the signal’s current value.

Auto Trait Implementations§

§

impl<T> !Freeze for Stamped<T>

§

impl<T> RefUnwindSafe for Stamped<T>
where T: RefUnwindSafe,

§

impl<T> Send for Stamped<T>
where T: Send,

§

impl<T> Sync for Stamped<T>
where T: Sync,

§

impl<T> Unpin for Stamped<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Stamped<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Stamped<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> CouplingPoint for T
where T: Sync + ?Sized,

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, 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.