Buffer

Trait Buffer 

Source
pub trait Buffer<T: Clone + Send>:
    Send
    + Sync
    + 'static {
    type Reader: BufferReader<T> + 'static;

    // Required methods
    fn new(cfg: &BufferCfg) -> Self
       where Self: Sized;
    fn push(&self, value: T);
    fn subscribe(&self) -> Self::Reader;
}
Expand description

Static buffer trait for concrete implementations

Provides push/subscribe operations for typed buffers. Readers are owned and can outlive the subscription call (required for spawned tasks).

Trait bounds ensure thread-safety and 'static lifetime for async runtimes.

See aimdb_tokio_adapter::TokioRingBuffer for implementation example.

Required Associated Types§

Source

type Reader: BufferReader<T> + 'static

Reader type for consuming values

Each subscribe() call returns an independent owned reader.

Required Methods§

Source

fn new(cfg: &BufferCfg) -> Self
where Self: Sized,

Creates a new buffer with the given configuration

§Panics

May panic if configuration is invalid (call cfg.validate() first)

Source

fn push(&self, value: T)

Push a value into the buffer (non-blocking)

Behavior depends on buffer type:

  • SPMC Ring: Overwrites oldest value if full
  • SingleLatest: Overwrites previous value
  • Mailbox: Overwrites pending value if not consumed
Source

fn subscribe(&self) -> Self::Reader

Create a new independent reader for a consumer

Each reader maintains its own position and can consume at its own pace. The returned reader is owned and can outlive this reference.

Implementors§