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§
Sourcetype Reader: BufferReader<T> + 'static
type Reader: BufferReader<T> + 'static
Reader type for consuming values
Each subscribe() call returns an independent owned reader.
Required Methods§
Sourcefn new(cfg: &BufferCfg) -> Selfwhere
Self: Sized,
fn new(cfg: &BufferCfg) -> Selfwhere
Self: Sized,
Creates a new buffer with the given configuration
§Panics
May panic if configuration is invalid (call cfg.validate() first)
Sourcefn push(&self, value: T)
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
Sourcefn subscribe(&self) -> Self::Reader
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.
§Fresh-subscriber semantics (SingleLatest)
For a SingleLatest buffer, a fresh
subscriber observes the buffer’s current value once, as if it had been
pushed right after subscription; if nothing has been produced yet, it
waits. A late subscriber to state wants the current state, not just
future changes. This rule holds identically across every runtime adapter
and is enforced by
test_support::assert_single_latest_contract.
SpmcRing and Mailbox readers have no such replay: a fresh subscriber
only sees values produced after it subscribes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".