1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::error::BatchError;

pub trait ItemReader<R> {
    fn read(&self) -> Option<Result<R, BatchError>>;
}

pub trait ItemProcessor<R, W> {
    fn process<'a>(&'a self, item: &'a R) -> W;
}

pub trait ItemWriter<W> {
    fn write(&self, item: &W) -> Result<(), BatchError>;
    fn flush(&self) -> Result<(), BatchError>;
    fn open(&self) -> Result<(), BatchError> {
        Ok(())
    }
    fn update(&self, _is_first_item: bool) -> Result<(), BatchError> {
        Ok(())
    }
    fn close(&self) -> Result<(), BatchError> {
        Ok(())
    }
}

pub struct DefaultProcessor {}

impl<R: Clone> ItemProcessor<R, R> for DefaultProcessor {
    fn process<'a>(&'a self, item: &'a R) -> R {
        item.clone()
    }
}