Struct CommandBuffer

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

Allocation-free storage for one pending input edge with a fixed lifetime.

A new edge always replaces the occupied slot; holding a button must not push again. Expiry occurs only on advancement, including zero-delta advancement: the historical remaining <= 1e-9 seconds boundary is preserved. Thus a positive lifetime at or below that boundary can be consumed before its first advance, just as with the legacy methods. See the module example for outcomes. Commands need only be Copy: admission and outcomes never compare payloads or require them to implement Debug or equality traits.

Implementations§

Source§

impl<T> CommandBuffer<T>
where T: Copy,

Source

pub fn new(lifetime: f32) -> Result<CommandBuffer<T>, LoopError>

Source

pub fn push(&mut self, command: T)

A new edge replaces the previous command. Holding a button is not an edge.

Source

pub fn push_checked(&mut self, command: T) -> PushOutcome<T>

Admit a fresh edge, returning the displaced value only on replacement.

The one-slot capacity is deliberate: insertion cannot fail after checked construction. Even an equal-valued edge replaces and refreshes the slot. See the module example; this is the implementation used by Self::push.

Source

pub fn advance(&mut self, dt: f32) -> Result<(), LoopError>

Advance simulation time, discarding the detailed expiry outcome.

Source

pub fn advance_checked( &mut self, dt: f32, ) -> Result<AdvanceOutcome<T>, LoopError>

Advance once per executed tick, reporting a removed expired value once.

dt must be finite and in 0..=3600 seconds, even for an empty buffer. Invalid input returns LoopError::Invalid without changing any state. Expiry uses the existing inclusive 1e-9 seconds boundary, not a rounded inspection value. No expiry is cached for a later call to report again. See the module example; Self::advance shares this implementation.

Source

pub fn take_if(&mut self, ready: bool) -> Option<T>

Consume if ready, discarding the distinction between empty and gated.

Source

pub fn take_if_checked(&mut self, ready: bool) -> ConsumeOutcome<T>

Hand off a pending command only when the caller’s execution gate is open.

An empty slot reports Empty even for a closed gate. Gated changes no state and invokes no speculative callback. Executed clears the command and remaining life; it does not establish that the caller’s game rules accepted the action. See the module example and Self::take_if.

Source

pub fn clear(&mut self)

Discard any pending command and life, retaining the configured lifetime.

Source

pub fn pending(&self) -> Option<T>

Source

pub fn remaining_life(&self) -> Option<f64>

Read remaining seconds without consuming, advancing or checking expiry.

None means the slot is empty. Some preserves the internal f64 precision used by expiry, including a just-pushed sub-epsilon lifetime. Repeated inspection and closed gates cannot refresh the lifetime. See the module example for inspection before and after execution/expiry.

Trait Implementations§

Source§

impl<T> Clone for CommandBuffer<T>
where T: Clone + Copy,

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for CommandBuffer<T>
where T: Debug + Copy,

Source§

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

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

impl<T> Copy for CommandBuffer<T>
where T: Copy,

Auto Trait Implementations§

§

impl<T> Freeze for CommandBuffer<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for CommandBuffer<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> 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> 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, 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.