sea_streamer_socket/
producer_options.rs

1#[cfg(feature = "backend-file")]
2use sea_streamer_file::FileProducerOptions;
3#[cfg(feature = "backend-kafka")]
4use sea_streamer_kafka::KafkaProducerOptions;
5#[cfg(feature = "backend-redis")]
6use sea_streamer_redis::RedisProducerOptions;
7#[cfg(feature = "backend-stdio")]
8use sea_streamer_stdio::StdioProducerOptions;
9
10use sea_streamer_types::ProducerOptions;
11
12#[derive(Debug, Default, Clone)]
13/// `sea-streamer-socket` concrete type of ProducerOptions.
14pub struct SeaProducerOptions {
15    #[cfg(feature = "backend-kafka")]
16    kafka: KafkaProducerOptions,
17    #[cfg(feature = "backend-redis")]
18    redis: RedisProducerOptions,
19    #[cfg(feature = "backend-stdio")]
20    stdio: StdioProducerOptions,
21    #[cfg(feature = "backend-file")]
22    file: FileProducerOptions,
23}
24
25impl SeaProducerOptions {
26    #[cfg(feature = "backend-kafka")]
27    pub fn into_kafka_producer_options(self) -> KafkaProducerOptions {
28        self.kafka
29    }
30
31    #[cfg(feature = "backend-redis")]
32    pub fn into_redis_producer_options(self) -> RedisProducerOptions {
33        self.redis
34    }
35
36    #[cfg(feature = "backend-stdio")]
37    pub fn into_stdio_producer_options(self) -> StdioProducerOptions {
38        self.stdio
39    }
40
41    #[cfg(feature = "backend-file")]
42    pub fn into_file_producer_options(self) -> FileProducerOptions {
43        self.file
44    }
45
46    #[cfg(feature = "backend-kafka")]
47    /// Set options that only applies to Kafka
48    pub fn set_kafka_producer_options<F: FnOnce(&mut KafkaProducerOptions)>(&mut self, func: F) {
49        func(&mut self.kafka)
50    }
51
52    #[cfg(feature = "backend-redis")]
53    /// Set options that only applies to Redis
54    pub fn set_redis_producer_options<F: FnOnce(&mut RedisProducerOptions)>(&mut self, func: F) {
55        func(&mut self.redis)
56    }
57
58    #[cfg(feature = "backend-stdio")]
59    /// Set options that only applies to Stdio
60    pub fn set_stdio_producer_options<F: FnOnce(&mut StdioProducerOptions)>(&mut self, func: F) {
61        func(&mut self.stdio)
62    }
63
64    #[cfg(feature = "backend-file")]
65    /// Set options that only applies to File
66    pub fn set_file_producer_options<F: FnOnce(&mut FileProducerOptions)>(&mut self, func: F) {
67        func(&mut self.file)
68    }
69}
70
71impl ProducerOptions for SeaProducerOptions {}