pale/config.rs
1use std::time::Duration;
2
3use tokio_tungstenite::tungstenite::protocol::WebSocketConfig;
4
5/// The config used for [`Client`](crate::Client).
6///
7/// Controls the timeout [`Duration`]s, max retry attempts, etc.
8///
9/// Also contains the [`WebSocketConfig`] for the underlying socket.
10#[derive(Debug, Clone)]
11pub struct ClientConfig {
12 /// How many messages can be in any of the internal channels at once.
13 pub channel_capacity: usize,
14 /// How many reconnection attempts the client will attempt at most when connection is lost.
15 pub max_retry_attempts: i32,
16 /// The delay between each reconnection attempt.
17 pub retry_connection: Duration,
18 /// The timeout for each request to the server.
19 pub request_timeout: Duration,
20 /// An optional bearer token that will be added into a `Authorization` header on connection.
21 pub bearer_token: Option<String>,
22 /// Config for the underlying websocket.
23 pub ws_config: WebSocketConfig,
24}
25
26impl Default for ClientConfig {
27 fn default() -> Self {
28 Self {
29 channel_capacity: 8192,
30 max_retry_attempts: 36,
31 retry_connection: Duration::from_secs(10),
32 request_timeout: Duration::from_secs(15),
33 bearer_token: None,
34 ws_config: WebSocketConfig::default(),
35 }
36 }
37}
38
39impl ClientConfig {
40 /// Creates a default [`ClientConfig`] but with a `bearer_token` supplied.
41 pub fn with_bearer(bearer: &str) -> Self {
42 Self {
43 bearer_token: Some(bearer.to_string()),
44 ..Default::default()
45 }
46 }
47}