flare_core/client/builder/
base.rs1use crate::client::config::ClientConfig;
12use crate::common::compression::CompressionAlgorithm;
13use crate::common::config_types::{HeartbeatConfig, TlsConfig, TransportProtocol};
14use crate::common::device::DeviceInfo;
15use crate::common::protocol::SerializationFormat;
16use std::time::Duration;
17
18pub struct BaseClientBuilderConfig {
23 pub config: ClientConfig,
24}
25
26impl BaseClientBuilderConfig {
27 pub fn new(server_url: impl Into<String>) -> Self {
29 Self {
30 config: ClientConfig::new(server_url.into()),
31 }
32 }
33
34 #[must_use]
36 pub fn with_protocol(mut self, protocol: TransportProtocol) -> Self {
37 self.config.transport = protocol;
38 self
39 }
40
41 #[must_use]
43 pub fn with_protocol_race(mut self, protocols: Vec<TransportProtocol>) -> Self {
44 self.config = self.config.with_protocol_race(protocols);
45 self
46 }
47
48 #[must_use]
50 pub fn with_protocol_url(mut self, protocol: TransportProtocol, url: String) -> Self {
51 self.config = self.config.with_protocol_url(protocol, url);
52 self
53 }
54
55 #[must_use]
57 pub fn with_user_id(mut self, user_id: String) -> Self {
58 self.config = self.config.with_user_id(user_id);
59 self
60 }
61
62 #[must_use]
64 pub fn with_token(mut self, token: String) -> Self {
65 self.config = self.config.with_token(token);
66 self
67 }
68
69 #[must_use]
71 pub fn with_format(mut self, format: SerializationFormat) -> Self {
72 self.config = self.config.with_format(format);
73 self
74 }
75
76 #[must_use]
78 pub fn with_compression(mut self, compression: CompressionAlgorithm) -> Self {
79 self.config = self.config.with_compression(compression);
80 self
81 }
82
83 #[must_use]
85 pub fn force_format(mut self, format: SerializationFormat) -> Self {
86 self.config = self.config.force_format(format);
87 self
88 }
89
90 #[must_use]
92 pub fn force_compression(mut self, compression: CompressionAlgorithm) -> Self {
93 self.config = self.config.force_compression(compression);
94 self
95 }
96
97 #[must_use]
99 pub fn with_device_info(mut self, device_info: DeviceInfo) -> Self {
100 self.config = self.config.with_device_info(device_info);
101 self
102 }
103
104 #[must_use]
106 pub fn with_heartbeat(mut self, heartbeat: HeartbeatConfig) -> Self {
107 self.config = self.config.with_heartbeat(heartbeat);
108 self
109 }
110
111 #[must_use]
113 pub fn with_tls(mut self, tls: TlsConfig) -> Self {
114 self.config = self.config.with_tls(tls);
115 self
116 }
117
118 #[must_use]
120 pub fn with_connect_timeout(mut self, timeout: Duration) -> Self {
121 self.config = self.config.with_connect_timeout(timeout);
122 self
123 }
124
125 #[must_use]
127 pub fn with_race_timeout(mut self, timeout: Duration) -> Self {
128 self.config = self.config.with_race_timeout(timeout);
129 self
130 }
131
132 #[must_use]
134 pub fn with_reconnect_interval(mut self, interval: Duration) -> Self {
135 self.config = self.config.with_reconnect_interval(interval);
136 self
137 }
138
139 #[must_use]
141 pub fn with_max_reconnect_attempts(mut self, max: Option<u32>) -> Self {
142 self.config = self.config.with_max_reconnect_attempts(max);
143 self
144 }
145
146 #[must_use]
148 pub fn enable_router(mut self) -> Self {
149 self.config = self.config.enable_router();
150 self
151 }
152}