streamweave_transformers/zip/
zip_transformer.rs

1use std::marker::PhantomData;
2use streamweave::TransformerConfig;
3use streamweave_error::ErrorStrategy;
4
5/// A transformer that zips items from multiple streams into vectors.
6///
7/// This transformer collects items from multiple input streams and combines
8/// them into vectors, emitting one vector per combination of items from each stream.
9#[derive(Clone)]
10pub struct ZipTransformer<T: std::fmt::Debug + Clone + Send + Sync + 'static> {
11  /// Configuration for the transformer, including error handling strategy.
12  pub config: TransformerConfig<Vec<T>>,
13  /// Phantom data to track the type parameter.
14  pub _phantom: PhantomData<T>,
15}
16
17impl<T: std::fmt::Debug + Clone + Send + Sync + 'static> Default for ZipTransformer<T> {
18  fn default() -> Self {
19    Self::new()
20  }
21}
22
23impl<T: std::fmt::Debug + Clone + Send + Sync + 'static> ZipTransformer<T> {
24  /// Creates a new `ZipTransformer`.
25  pub fn new() -> Self {
26    Self {
27      config: TransformerConfig::<Vec<T>>::default(),
28      _phantom: PhantomData,
29    }
30  }
31
32  /// Sets the error handling strategy for this transformer.
33  ///
34  /// # Arguments
35  ///
36  /// * `strategy` - The error handling strategy to use.
37  pub fn with_error_strategy(mut self, strategy: ErrorStrategy<Vec<T>>) -> Self {
38    self.config.error_strategy = strategy;
39    self
40  }
41
42  /// Sets the name for this transformer.
43  ///
44  /// # Arguments
45  ///
46  /// * `name` - The name to assign to this transformer.
47  pub fn with_name(mut self, name: String) -> Self {
48    self.config.name = Some(name);
49    self
50  }
51}