streamweave_transformers/map/
map_transformer.rs1use streamweave::TransformerConfig;
2use streamweave_error::ErrorStrategy;
3
4pub struct MapTransformer<F, I, O>
9where
10 F: FnMut(I) -> O + Send + Clone + 'static,
11 I: std::fmt::Debug + Clone + Send + Sync + 'static,
12 O: std::fmt::Debug + Clone + Send + Sync + 'static,
13{
14 pub f: F,
16 pub config: TransformerConfig<I>,
18 pub _phantom_i: std::marker::PhantomData<I>,
20 pub _phantom_o: std::marker::PhantomData<O>,
22}
23
24impl<F, I, O> MapTransformer<F, I, O>
25where
26 F: FnMut(I) -> O + Send + Clone + 'static,
27 I: std::fmt::Debug + Clone + Send + Sync + 'static,
28 O: std::fmt::Debug + Clone + Send + Sync + 'static,
29{
30 pub fn new(f: F) -> Self {
36 Self {
37 f,
38 config: TransformerConfig::default(),
39 _phantom_i: std::marker::PhantomData,
40 _phantom_o: std::marker::PhantomData,
41 }
42 }
43
44 pub fn with_error_strategy(mut self, strategy: ErrorStrategy<I>) -> Self {
50 self.config.error_strategy = strategy;
51 self
52 }
53
54 pub fn with_name(mut self, name: String) -> Self {
60 self.config.name = Some(name);
61 self
62 }
63}
64
65impl<F, I, O> Clone for MapTransformer<F, I, O>
66where
67 F: FnMut(I) -> O + Send + Clone + 'static,
68 I: std::fmt::Debug + Clone + Send + Sync + 'static,
69 O: std::fmt::Debug + Clone + Send + Sync + 'static,
70{
71 fn clone(&self) -> Self {
72 Self {
73 f: self.f.clone(),
74 config: self.config.clone(),
75 _phantom_i: std::marker::PhantomData,
76 _phantom_o: std::marker::PhantomData,
77 }
78 }
79}