pub trait Processor {
type InputType;
// Required method
fn process<'life0, 'async_trait>(
&'life0 mut self,
data: Self::InputType,
metrics: Arc<MetricsCollection>,
) -> Pin<Box<dyn Future<Output = CarbonResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
A trait for defining asynchronous data processing within the pipeline.
The Processor
trait provides a single asynchronous method, process
, which is
responsible for handling data of a specific type (InputType
). This trait is designed
to be implemented by types that need to process data within the pipeline, allowing for
customized handling of different data types.
§Type Parameters
InputType
: The type of data that this processor will handle. This can represent a variety of data structures depending on the application’s specific needs.
§Required Methods
process
: Processes the specifiedInputType
data asynchronously, optionally updating associated metrics.
§Example
struct CustomProcessor;
#[async_trait]
impl Processor for CustomProcessor {
type InputType = DataType;
async fn process(
&mut self,
data: Self::InputType,
metrics: Arc<MetricsCollection>,
) -> CarbonResult<()> {
// Perform data processing logic
// Optionally, update metrics
for metric in &metrics {
metric.increment_counter("processed_items", 1).await?;
}
Ok(())
}
}