Skip to main content

BatchProcessor

Trait BatchProcessor 

Source
pub trait BatchProcessor: Sync {
    type Input: Sync;
    type Output: Send;
    type Error: Send;

    // Required method
    fn process(&self, input: &Self::Input) -> Result<Self::Output, Self::Error>;
}
Available on crate features worker-batch or worker-pool or worker only.
Expand description

Trait for parallel-safe message processing.

Implement this with a struct that holds only & references to immutable dependencies. The process method must be pure – no mutable state, no I/O, no .await. Safe for rayon par_iter().

The struct is typically created per-batch in the event loop (borrows released before the sequential phase begins). The borrow checker enforces this.

Required Associated Types§

Source

type Input: Sync

Input message type (e.g. KafkaMessage, HttpRequest).

Source

type Output: Send

Successful processing result (e.g. ProcessedMessage, CompressedBatch).

Source

type Error: Send

Error type for processing failures.

Required Methods§

Source

fn process(&self, input: &Self::Input) -> Result<Self::Output, Self::Error>

Process a single input. Must be pure – no mutation, no I/O.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§