Module commands

Expand description

See commands for the system contract and examples. Deferred host/world mutations at an explicit synchronization boundary.

The command count is bounded; closures own arbitrary host-controlled payloads. Inspection reports queue state and activity without invoking commands. Accepted means queued, not successfully applied. Capacity rejection returns ownership to the caller and does not reorder retained commands.

Apply and drain consume commands in insertion order. Apply removes each command immediately before invoking it. Panics propagate: earlier changes and any changes made by the panicking command remain, that command is consumed, and all later commands stay queued. There is no rollback or automatic retry. A lazy drain only removes commands actually yielded; dropping it leaves the rest queued.

FallibleCommandBuffer adds typed domain errors with an explicit CommandFailurePolicy. Its error callback receives the caller-supplied command ID and owned error without an intermediate error collection.

use ferravex_engine::commands::CommandBuffer;

let mut commands = CommandBuffer::new(2);
assert_eq!(commands.capacity(), 2);
assert!(commands.push(|world: &mut Vec<u32>| world.push(10)).is_ok());
assert!(commands.push(|world: &mut Vec<u32>| world.push(20)).is_ok());
assert!(commands.is_full());
assert_eq!(commands.remaining_capacity(), 0);
let rejected = commands.push(|world: &mut Vec<u32>| world.push(30)).err().unwrap();
assert_eq!(commands.metrics().accepted, 2);
assert_eq!(commands.metrics().rejected, 1);

let mut world = Vec::new();
let outcome = commands.apply_report(&mut world, 1);
assert_eq!((outcome.applied, outcome.remaining), (1, 1));
assert!(commands.push(rejected).is_ok());
assert_eq!(commands.apply(&mut world, usize::MAX), 2);
assert_eq!(world, [10, 20, 30]);
assert!(commands.is_empty());
let interval = commands.reset_metrics();
assert_eq!((interval.started, interval.applied), (3, 3));
assert_eq!(interval.high_water_mark, 2);
assert_eq!(commands.metrics().accepted, 0);

Structs§

CommandApplyOutcome
A completed, bounded apply operation. A panic propagates instead of returning an outcome; CommandBuffer::metrics still records its partial progress.
CommandBuffer
A bounded FIFO queue of opaque deferred mutations.
CommandBufferMetrics
Queue activity since construction or the last metrics reset.
CommandDrain
A lazy, bounded FIFO drain created by CommandBuffer::drain_up_to.
CommandDrainOutcome
A snapshot of a lazy drain’s progress, with no command execution implied.
CommandFailure
A consumed command’s caller-supplied ID and original, owned domain error.
FallibleCommandApplyOutcome
Counts from one normally returning fallible apply.
FallibleCommandBuffer
A bounded FIFO queue of fallible deferred mutations.
FallibleCommandBufferMetrics
Fallible queue activity since construction or the last metrics reset.

Enums§

CommandFailurePolicy
How a fallible apply responds to a command returning Err.

Type Aliases§

Command
An owned, opaque deferred mutation. Calling it consumes it exactly once.