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
use std::time::Duration;

use super::ReconnectStrategy;

const DEFAULT_SILENCE_DURATION: Duration = Duration::from_secs(20);
const MAXIMUM_SILENCE_DURATION: Duration = Duration::from_millis(68719476734);

/// Represents a general-purpose set of properties tied with a client instance.
#[derive(Clone, Debug)]
pub struct ClientConfig {
    /// Strategy to use when reconnecting to a server.
    pub reconnect_strategy: ReconnectStrategy,

    /// If true, the client will shutdown its internal task once dropped, resulting in all channels
    /// no longer receiving data.
    pub shutdown_on_drop: bool,

    /// A maximum duration to not receive any response/heartbeat from a server before deeming the
    /// server as lost and triggering a reconnect.
    pub silence_duration: Duration,
}

impl ClientConfig {
    pub fn with_maximum_silence_duration(self) -> Self {
        Self {
            reconnect_strategy: self.reconnect_strategy,
            shutdown_on_drop: self.shutdown_on_drop,
            silence_duration: MAXIMUM_SILENCE_DURATION,
        }
    }
}

impl Default for ClientConfig {
    fn default() -> Self {
        Self {
            reconnect_strategy: ReconnectStrategy::Fail,
            shutdown_on_drop: false,
            silence_duration: DEFAULT_SILENCE_DURATION,
        }
    }
}