carbon_core/processor.rs
1//! Processor trait — user-defined handler executed for each decoded update.
2//!
3//! # Flow
4//!
5//! 1. A datasource emits an `Update` into the pipeline.
6//! 2. Matching pipes filter and route the update.
7//! 3. Each pipe decodes (or forwards) and invokes `Processor::process`.
8//!
9//! # Notes
10//!
11//! - Uses native `impl Future` (Rust 1.75+) since `Processor` is always used as
12//! a generic bound, avoiding per-call boxing.
13//! - Dyn-dispatched traits in the crate (`Datasource`, `*Pipes`) retain
14//! `#[async_trait]` due to current async trait object limitations.
15
16use {crate::error::CarbonResult, std::future::Future};
17
18/// Async handler invoked for each decoded update of type `T`.
19///
20/// Registered via `PipelineBuilder` (`account`, `instruction`,
21/// `transaction`, `account_deletions`, `block_details`). The pipeline
22/// awaits `process` for every update that passes filters.
23///
24/// # Errors
25///
26/// Returning `Err` is logged and counted in metrics; processing continues.
27/// Use for recoverable failures, not pipeline termination.
28pub trait Processor<T>
29where
30 T: Sync,
31{
32 fn process(&mut self, data: &T) -> impl Future<Output = CarbonResult<()>> + Send;
33}