Skip to main content

Adapter

Trait Adapter 

Source
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::push per event in hot path
  • String allocation per event
  • Any heap allocation scaling with event count

Required Methods§

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,

Initialize the adapter.

Called once before any other methods. Use this to establish connections, validate configuration, etc.

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,

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 safe
  • AdapterError::Fatal: Unrecoverable error, adapter is broken
  • AdapterError::Backpressure: Backend overloaded, slow down
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,

Force flush any buffered data.

Some adapters may buffer writes for efficiency. This method forces all buffered data to be persisted.

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,

Gracefully shut down the adapter.

This should flush any pending data and close connections.

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,

Poll events from a single shard.

§Parameters
  • shard_id: The shard to poll
  • from_id: Start cursor (exclusive). None means from the beginning.
  • limit: Maximum number of events to return
§Returns

A ShardPollResult containing the events and pagination info.

Source

fn name(&self) -> &'static str

Get the adapter name (for logging/metrics).

Provided Methods§

Source

fn is_healthy<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if the adapter is healthy.

Returns true if the adapter can accept batches.

Trait Implementations§

Source§

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,

Initialize the adapter. Read more
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,

Process a batch of events. Read more
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,

Force flush any buffered data. Read more
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,

Gracefully shut down the adapter. Read more
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,

Poll events from a single shard. Read more
Source§

fn name(&self) -> &'static str

Get the adapter name (for logging/metrics).
Source§

fn is_healthy<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if the adapter is healthy. Read more

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.

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,

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,

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,

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,

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,

Source§

fn name(&self) -> &'static str

Source§

fn is_healthy<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§