1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#[cfg(feature = "backend-file")]
use sea_streamer_file::FileProducerOptions;
#[cfg(feature = "backend-kafka")]
use sea_streamer_kafka::KafkaProducerOptions;
#[cfg(feature = "backend-redis")]
use sea_streamer_redis::RedisProducerOptions;
#[cfg(feature = "backend-stdio")]
use sea_streamer_stdio::StdioProducerOptions;

use sea_streamer_types::ProducerOptions;

#[derive(Debug, Default, Clone)]
/// `sea-streamer-socket` concrete type of ProducerOptions.
pub struct SeaProducerOptions {
    #[cfg(feature = "backend-kafka")]
    kafka: KafkaProducerOptions,
    #[cfg(feature = "backend-redis")]
    redis: RedisProducerOptions,
    #[cfg(feature = "backend-stdio")]
    stdio: StdioProducerOptions,
    #[cfg(feature = "backend-file")]
    file: FileProducerOptions,
}

impl SeaProducerOptions {
    #[cfg(feature = "backend-kafka")]
    pub fn into_kafka_producer_options(self) -> KafkaProducerOptions {
        self.kafka
    }

    #[cfg(feature = "backend-redis")]
    pub fn into_redis_producer_options(self) -> RedisProducerOptions {
        self.redis
    }

    #[cfg(feature = "backend-stdio")]
    pub fn into_stdio_producer_options(self) -> StdioProducerOptions {
        self.stdio
    }

    #[cfg(feature = "backend-file")]
    pub fn into_file_producer_options(self) -> FileProducerOptions {
        self.file
    }

    #[cfg(feature = "backend-kafka")]
    /// Set options that only applies to Kafka
    pub fn set_kafka_producer_options<F: FnOnce(&mut KafkaProducerOptions)>(&mut self, func: F) {
        func(&mut self.kafka)
    }

    #[cfg(feature = "backend-redis")]
    /// Set options that only applies to Redis
    pub fn set_redis_producer_options<F: FnOnce(&mut RedisProducerOptions)>(&mut self, func: F) {
        func(&mut self.redis)
    }

    #[cfg(feature = "backend-stdio")]
    /// Set options that only applies to Stdio
    pub fn set_stdio_producer_options<F: FnOnce(&mut StdioProducerOptions)>(&mut self, func: F) {
        func(&mut self.stdio)
    }

    #[cfg(feature = "backend-file")]
    /// Set options that only applies to File
    pub fn set_file_producer_options<F: FnOnce(&mut FileProducerOptions)>(&mut self, func: F) {
        func(&mut self.file)
    }
}

impl ProducerOptions for SeaProducerOptions {}