streamweave_tempfile/consumers/
tempfile_consumer.rs

1use streamweave::ConsumerConfig;
2use streamweave_error::ErrorStrategy;
3
4/// A consumer that writes items to a temporary file.
5///
6/// The temporary file is managed externally and will be cleaned up when dropped.
7pub struct TempFileConsumer {
8  /// The temporary file path
9  pub path: std::path::PathBuf,
10  /// Configuration for the consumer
11  pub config: ConsumerConfig<String>,
12}
13
14impl TempFileConsumer {
15  /// Creates a new `TempFileConsumer` from a temporary file path.
16  ///
17  /// # Arguments
18  ///
19  /// * `path` - Path to the temporary file
20  pub fn new(path: std::path::PathBuf) -> Self {
21    Self {
22      path,
23      config: ConsumerConfig::default(),
24    }
25  }
26
27  /// Sets the error handling strategy.
28  pub fn with_error_strategy(mut self, strategy: ErrorStrategy<String>) -> Self {
29    self.config.error_strategy = strategy;
30    self
31  }
32
33  /// Sets the name for this consumer.
34  pub fn with_name(mut self, name: String) -> Self {
35    self.config.name = name;
36    self
37  }
38}