aws_lambda_log_proxy/processor/
builder.rs1use crate::{SimpleProcessor, SinkHandle};
2
3pub struct SimpleProcessorBuilder<T, S> {
4 pub transformer: T,
6 pub sink: S,
8}
9
10impl SimpleProcessorBuilder<fn(String) -> Option<String>, ()> {
11 pub fn new() -> Self {
13 Self {
14 transformer: Some,
15 sink: (),
16 }
17 }
18}
19
20impl Default for SimpleProcessorBuilder<fn(String) -> Option<String>, ()> {
21 fn default() -> Self {
22 Self::new()
23 }
24}
25
26impl<T, S> SimpleProcessorBuilder<T, S> {
27 pub fn transformer<N: FnMut(String) -> Option<String> + Send + 'static>(
31 self,
32 transformer: N,
33 ) -> SimpleProcessorBuilder<N, S> {
34 SimpleProcessorBuilder {
35 transformer,
36 sink: self.sink,
37 }
38 }
39
40 pub fn sink(self, sink: SinkHandle) -> SimpleProcessorBuilder<T, SinkHandle> {
42 SimpleProcessorBuilder {
43 transformer: self.transformer,
44 sink,
45 }
46 }
47}
48
49impl<T: FnMut(String) -> Option<String> + Send + 'static> SimpleProcessorBuilder<T, SinkHandle> {
50 pub fn build(self) -> SimpleProcessor<T> {
52 SimpleProcessor::new(self.transformer, self.sink)
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 macro_rules! assert_unit {
61 ($unit:expr) => {
62 let _: () = $unit;
63 };
64 }
65
66 #[test]
67 fn default_transformer() {
68 let processor = SimpleProcessorBuilder::default();
69 assert_unit!(processor.sink);
70
71 let text = "test".to_string();
72 let transformed = (processor.transformer)(text.clone());
73 assert_eq!(transformed, Some(text));
75 }
76}