distant_net/client/
config.rs

1use std::time::Duration;
2
3use super::ReconnectStrategy;
4
5const DEFAULT_SILENCE_DURATION: Duration = Duration::from_secs(20);
6const MAXIMUM_SILENCE_DURATION: Duration = Duration::from_millis(68719476734);
7
8/// Represents a general-purpose set of properties tied with a client instance.
9#[derive(Clone, Debug)]
10pub struct ClientConfig {
11    /// Strategy to use when reconnecting to a server.
12    pub reconnect_strategy: ReconnectStrategy,
13
14    /// If true, the client will shutdown its internal task once dropped, resulting in all channels
15    /// no longer receiving data.
16    pub shutdown_on_drop: bool,
17
18    /// A maximum duration to not receive any response/heartbeat from a server before deeming the
19    /// server as lost and triggering a reconnect.
20    pub silence_duration: Duration,
21}
22
23impl ClientConfig {
24    pub fn with_maximum_silence_duration(self) -> Self {
25        Self {
26            reconnect_strategy: self.reconnect_strategy,
27            shutdown_on_drop: self.shutdown_on_drop,
28            silence_duration: MAXIMUM_SILENCE_DURATION,
29        }
30    }
31}
32
33impl Default for ClientConfig {
34    fn default() -> Self {
35        Self {
36            reconnect_strategy: ReconnectStrategy::Fail,
37            shutdown_on_drop: false,
38            silence_duration: DEFAULT_SILENCE_DURATION,
39        }
40    }
41}