Skip to main content

ItemProcessor

Trait ItemProcessor 

Source
pub trait ItemProcessor<I, O> {
    // Required method
    fn process(&self, item: &I) -> ItemProcessorResult<O>;
}
Expand description

A trait for processing items.

This trait defines the contract for components that transform or process items in a batch processing pipeline. It takes an input item of type R and produces an output item of type W.

§Design Pattern

This follows the Strategy Pattern, allowing different processing strategies to be interchangeable while maintaining a consistent interface.

§Type Parameters

  • R: The input item type
  • W: The output item type

§Example

use spring_batch_rs::core::item::{ItemProcessor, ItemProcessorResult};
use spring_batch_rs::error::BatchError;

struct UppercaseProcessor;

impl ItemProcessor<String, String> for UppercaseProcessor {
    fn process(&self, item: &String) -> ItemProcessorResult<String> {
        Ok(item.to_uppercase())
    }
}

Required Methods§

Source

fn process(&self, item: &I) -> ItemProcessorResult<O>

Processes an item and returns the processed result.

§Parameters
  • item: The item to process
§Returns
  • Ok(processed_item) when the item is successfully processed
  • Err(BatchError) when an error occurs during processing

Implementors§