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: 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: 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.

§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: 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

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: 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§