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,
impl<T> CommandBuffer<T>where
T: Copy,
pub fn new(lifetime: f32) -> Result<CommandBuffer<T>, LoopError>
Sourcepub fn push(&mut self, command: T)
pub fn push(&mut self, command: T)
A new edge replaces the previous command. Holding a button is not an edge.
Sourcepub fn push_checked(&mut self, command: T) -> PushOutcome<T>
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.
Sourcepub fn advance(&mut self, dt: f32) -> Result<(), LoopError>
pub fn advance(&mut self, dt: f32) -> Result<(), LoopError>
Advance simulation time, discarding the detailed expiry outcome.
Sourcepub fn advance_checked(
&mut self,
dt: f32,
) -> Result<AdvanceOutcome<T>, LoopError>
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.
Sourcepub fn take_if(&mut self, ready: bool) -> Option<T>
pub fn take_if(&mut self, ready: bool) -> Option<T>
Consume if ready, discarding the distinction between empty and gated.
Sourcepub fn take_if_checked(&mut self, ready: bool) -> ConsumeOutcome<T>
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.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Discard any pending command and life, retaining the configured lifetime.
pub fn pending(&self) -> Option<T>
Sourcepub fn remaining_life(&self) -> Option<f64>
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>
impl<T> Clone for CommandBuffer<T>
Source§fn clone(&self) -> CommandBuffer<T>
fn clone(&self) -> CommandBuffer<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more