pub trait Adapter: Send + Sync {
// Required methods
fn init<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn on_batch<'life0, 'async_trait>(
&'life0 self,
batch: Arc<Batch>,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn poll_shard<'life0, 'life1, 'async_trait>(
&'life0 self,
shard_id: u16,
from_id: Option<&'life1 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<ShardPollResult, AdapterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn name(&self) -> &'static str;
// Provided method
fn is_healthy<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Adapter trait for durable event storage.
§Memory Allocation Constraint
Adapters MUST NOT allocate memory per-event. Allowed allocations:
- Per-batch buffer allocation (reusable)
- Static/pooled buffers
- Connection resources
Forbidden:
Vec::pushper event in hot path- String allocation per event
- Any heap allocation scaling with event count
Required Methods§
Sourcefn init<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn init<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Initialize the adapter.
Called once before any other methods. Use this to establish connections, validate configuration, etc.
Sourcefn on_batch<'life0, 'async_trait>(
&'life0 self,
batch: Arc<Batch>,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_batch<'life0, 'async_trait>(
&'life0 self,
batch: Arc<Batch>,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process a batch of events.
The adapter must persist all events in the batch atomically (all or nothing). Events must be stored in order within the batch.
batch is passed as Arc<Batch> so the dispatch retry loop
can clone cheaply (refcount bump) instead of deep-cloning the
events Vec on every attempt — the common path is retries == 0 so the prior batch.clone() was almost always wasted.
Implementations that only read events (the overwhelming
majority) pay nothing for the wrap; the one that genuinely
consumes can Arc::try_unwrap and fall back to clone on
contention.
§Errors
AdapterError::Transient: Temporary failure, retry is safeAdapterError::Fatal: Unrecoverable error, adapter is brokenAdapterError::Backpressure: Backend overloaded, slow down
Sourcefn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Force flush any buffered data.
Some adapters may buffer writes for efficiency. This method forces all buffered data to be persisted.
Sourcefn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gracefully shut down the adapter.
This should flush any pending data and close connections.
Sourcefn poll_shard<'life0, 'life1, 'async_trait>(
&'life0 self,
shard_id: u16,
from_id: Option<&'life1 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<ShardPollResult, AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn poll_shard<'life0, 'life1, 'async_trait>(
&'life0 self,
shard_id: u16,
from_id: Option<&'life1 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<ShardPollResult, AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Provided Methods§
Trait Implementations§
Source§impl Adapter for Box<dyn Adapter>
Wrapper to make Box<dyn Adapter> implement Adapter.
impl Adapter for Box<dyn Adapter>
Wrapper to make Box<dyn Adapter> implement Adapter.
Source§fn init<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn init<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn on_batch<'life0, 'async_trait>(
&'life0 self,
batch: Arc<Batch>,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_batch<'life0, 'async_trait>(
&'life0 self,
batch: Arc<Batch>,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn poll_shard<'life0, 'life1, 'async_trait>(
&'life0 self,
shard_id: u16,
from_id: Option<&'life1 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<ShardPollResult, AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn poll_shard<'life0, 'life1, 'async_trait>(
&'life0 self,
shard_id: u16,
from_id: Option<&'life1 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<ShardPollResult, AdapterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Adapter for Box<dyn Adapter>
Wrapper to make Box<dyn Adapter> implement Adapter.
impl Adapter for Box<dyn Adapter>
Wrapper to make Box<dyn Adapter> implement Adapter.