Expand description
Core IndexBus algorithms built on top of the v1 ABI layouts.
This crate provides safe(ish) APIs for initializing and operating on the shared-memory
layouts defined in indexbus-abi.
- Layout structs live in
indexbus-abi(Rust source of truth; C headers generated). - This crate provides algorithms and handles (SPSC/MPSC events, fanout router, state stream).
§Safety model
Handles in this crate are thin wrappers around raw pointers to ABI layouts (typically memory-mapped shared memory). They are “safe” to call in the Rust sense only if you uphold the contracts documented on each type:
- The mapped layout must outlive all handles derived from it.
- You must not concurrently call APIs that require single-threaded access (most handles are
intentionally not
Sync). - Mappings should be validated with
validate_shared_layout,validate_fanout_layout,validate_state_layout, etc. before use (especially across process boundaries).
§Minimal SPSC example
use indexbus_core::{init_shared_layout, split_spsc, SharedLayoutCell};
use indexbus_abi::layouts::SharedLayout;
// SharedLayout is large; allocate it on the heap to avoid huge stack frames.
let mut shared: Box<SharedLayout> = Box::new(unsafe { core::mem::zeroed() });
init_shared_layout(&mut shared);
let cell = SharedLayoutCell::from_mut(&mut shared);
let (tx, rx) = split_spsc(cell).unwrap();
tx.publish(b"hi").unwrap();
let mut out = [0u8; 256];
let n = rx.try_recv_into(&mut out).unwrap().unwrap();
assert_eq!(&out[..n], b"hi");Re-exports§
pub use state::StateLayoutCell;pub use state::StatePublisher;pub use state::StateReader;pub use validate::validate_fanout_layout;pub use validate::validate_journal_layout4;pub use validate::validate_sequencer_layout;pub use validate::validate_state_layout;
Modules§
- prelude
- Curated prelude for downstream users.
- state
- State-stream publisher/reader algorithms.
- validate
- Runtime layout validation helpers.
Structs§
- Chain
Mpsc Consumer - MPSC consumer handle over an explicit
(pool, queue)pair. - Chain
Mpsc Producer - MPSC producer handle over an explicit
(pool, queue)pair. - Chain
Spsc Receiver - SPSC receiver handle over an explicit
(pool, queue)pair. - Chain
Spsc Sender - SPSC sender handle over an explicit
(pool, queue)pair. - Events
Slot - Owned handle to an Events slot (slot index + pool pointer).
- Fanout
Consumer - Consumer handle for a fanout events region.
- Fanout
Mpsc Producer - Multi-producer handle for publishing into a fanout layout.
- Fanout
Producer - SPSC producer handle for a fanout events region.
- Fanout
Router - Fanout router handle.
- Mpsc
Consumer - MPSC consumer handle for a
SharedLayoutevents region. - Mpsc
Producer - MPSC producer handle for a
SharedLayoutevents region. - Publish
Slot Error - Error returned by
publish_slotAPIs when the slot cannot be forwarded. - Route
Once Result - Result of a single
FanoutRouterrouting step. - Shared
Fanout Layout Cell SharedFanoutLayout<N>wrapper that explicitly opts into interior mutability.- Shared
Layout Cell SharedLayoutwrapper that explicitly opts into interior mutability.- Spin
Wait - no_std-friendly spin-only wait strategy.
- Spsc
Receiver - SPSC consumer handle for a
SharedLayoutevents region. - Spsc
Sender - SPSC producer handle for a
SharedLayoutevents region. - StdBackoff
- std-only: spin, then yield, then sleep with capped exponential backoff.
- Yield
Wait - std-only: cooperative yield-only wait strategy.
Enums§
- Error
- Core error type returned by the low-level region handles.
- Publish
With Error - Error returned by
publish_withAPIs. - Recv
With Error - Error returned by
try_recv_withAPIs. - Router
Mode - Routing policy for a single message.
- Router
Source - Selects which producer queue the router drains from.
Constants§
- INDEXBUS_
EMPTY_ FREE_ U32 - Re-export ABI constants for convenience. Free-list empty sentinel.
- INDEXBUS_
FANOUT_ CONSUMERS_ DEFAULT - Re-export ABI constants for convenience. Default fanout consumer count used by examples.
- INDEXBUS_
QUEUE_ CAPACITY - Re-export ABI constants for convenience. Ring queue capacity (MUST be power-of-two).
- INDEXBUS_
SLOTS_ CAPACITY - Re-export ABI constants for convenience. Number of slots in the shared pool.
- INDEXBUS_
SLOT_ DATA_ SIZE - Re-export ABI constants for convenience. v1 constants (must match generated C headers). Fixed bytes available per slot payload.
Traits§
- Wait
Strategy - Progressive backoff when polling.
Functions§
- cpu_
relax - Hint to the processor that we are in a spin-wait loop.
- fanout_
handles - Create handles over a fanout layout.
- fanout_
mpsc_ producer - Create an MPSC producer handle over a fanout layout.
- init_
shared_ fanout_ layout - Initialize a shared fanout events layout in-place with default v1 capabilities.
- init_
shared_ fanout_ layout_ with_ layout_ bytes - Initialize a shared fanout events layout in-place.
- init_
shared_ layout - Initialize a shared events layout in-place with default v1 capabilities.
- init_
shared_ layout_ with_ layout_ bytes - Initialize a shared events layout in-place.
- split_
chain_ ⚠mpsc - Create MPSC producer/consumer handles over a shared slot pool and a specific MPSC queue.
- split_
chain_ ⚠spsc - Create SPSC sender/receiver handles over a shared slot pool and a specific queue.
- split_
mpsc - Create MPSC producer/consumer handles over a shared layout.
- split_
spsc - Create SPSC sender/receiver handles over a shared layout.