leyline/core/config/
pool.rs1use std::time::Duration;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[non_exhaustive]
5pub struct PoolConfig {
6 pub(crate) idle_timeout: Duration,
7 pub(crate) max_connections: usize,
8 pub(crate) max_h1_conns_per_host: usize,
9 pub(crate) keepalive: bool,
10 pub(crate) h2_ping_after_idle: Option<Duration>,
11 pub(crate) h2_ping_timeout: Duration,
12}
13
14impl Default for PoolConfig {
15 fn default() -> Self {
16 Self {
17 idle_timeout: crate::pool::DEFAULT_IDLE_TIMEOUT,
18 max_connections: crate::pool::DEFAULT_MAX_CONNECTIONS,
19 max_h1_conns_per_host: crate::pool::DEFAULT_MAX_H1_CONNS_PER_HOST,
20 keepalive: true,
21 h2_ping_after_idle: crate::pool::DEFAULT_H2_PING_AFTER_IDLE,
22 h2_ping_timeout: crate::pool::DEFAULT_H2_PING_TIMEOUT,
23 }
24 }
25}
26
27impl PoolConfig {
28 pub fn new() -> Self {
29 Self::default()
30 }
31
32 pub fn idle_timeout(mut self, d: Duration) -> Self {
33 self.idle_timeout = d;
34 self
35 }
36
37 pub fn max_connections(mut self, n: usize) -> Self {
38 self.max_connections = n;
39 self
40 }
41
42 pub fn max_h1_conns_per_host(mut self, n: usize) -> Self {
43 self.max_h1_conns_per_host = n;
44 self
45 }
46
47 pub fn keepalive(mut self, on: bool) -> Self {
48 self.keepalive = on;
49 self
50 }
51
52 pub fn h2_ping_after_idle(mut self, d: impl Into<Option<Duration>>) -> Self {
53 self.h2_ping_after_idle = d.into();
54 self
55 }
56
57 pub fn h2_ping_timeout(mut self, d: Duration) -> Self {
58 self.h2_ping_timeout = d;
59 self
60 }
61}