Skip to main content

LatestBuf

Struct LatestBuf 

Source
pub struct LatestBuf<T: Copy> { /* private fields */ }
Expand description

Three-slot freshness-first SPSC snapshot channel.

LatestBuf<T> has fixed storage for three T values and never allocates. Publishing always succeeds and takes one atomic exchange. Taking is also bounded to one load, at most one exchange, and at most one payload copy.

Implementations§

Source§

impl<T: Copy> LatestBuf<T>

Source

pub const fn new() -> Self

Create an empty channel.

On normal builds this is const, so a channel may live in a static. Under --cfg loom it is non-const because Loom’s primitives are not const-constructible.

Source

pub fn try_producer(&self) -> Option<Producer<'_, T>>

Try to acquire the unique producer role.

Returns None while another producer handle is active. Dropping the active handle makes the role available without resetting its state.

The role is held until the active handle is dropped — a handle that is forgotten, or owned by an execution context destroyed without running destructors, leaves the role held with channel state intact. There is deliberately no out-of-band role reset: a forced release could free a role while a live handle still exists, defeating the exclusive ownership that soundness rests on (contract non-promise X8). Handle lifetime is the application’s property; the channel observes only acquisition and drop.

Source

pub fn try_consumer(&self) -> Option<Consumer<'_, T>>

Try to acquire the unique consumer role.

Returns None while another consumer handle is active. Dropping the active handle makes the role available without resetting its state.

Role recovery follows the same boundary as Self::try_producer: held until dropped, no out-of-band reset, handle lifetime owned by the application (contract non-promise X8).

Trait Implementations§

Source§

impl<T: Copy> Debug for LatestBuf<T>

Source§

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

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

impl<T: Copy> Default for LatestBuf<T>

Source§

fn default() -> Self

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

impl<T: Copy + Send> Sync for LatestBuf<T>

Auto Trait Implementations§

§

impl<T> !Freeze for LatestBuf<T>

§

impl<T> !RefUnwindSafe for LatestBuf<T>

§

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

§

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

§

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

§

impl<T> UnwindSafe for LatestBuf<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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.