lettre/transport/smtp/pool/
mod.rs

1use std::time::Duration;
2
3#[cfg(any(feature = "tokio1", feature = "async-std1"))]
4pub(super) mod async_impl;
5pub(super) mod sync_impl;
6
7/// Configuration for a connection pool
8#[derive(Debug, Clone)]
9#[allow(missing_copy_implementations)]
10#[cfg_attr(docsrs, doc(cfg(feature = "pool")))]
11pub struct PoolConfig {
12    min_idle: u32,
13    max_size: u32,
14    idle_timeout: Duration,
15}
16
17impl PoolConfig {
18    /// Create a new pool configuration with default values
19    pub fn new() -> Self {
20        Self::default()
21    }
22
23    /// Minimum number of idle connections
24    ///
25    /// Defaults to `0`
26    pub fn min_idle(mut self, min_idle: u32) -> Self {
27        self.min_idle = min_idle;
28        self
29    }
30
31    /// Maximum number of pooled connections
32    ///
33    /// Defaults to `10`
34    pub fn max_size(mut self, max_size: u32) -> Self {
35        self.max_size = max_size;
36        self
37    }
38
39    /// Connection timeout
40    ///
41    /// Defaults to `30 seconds`
42    #[doc(hidden)]
43    #[deprecated(note = "The Connection timeout is already configured on the SMTP transport")]
44    pub fn connection_timeout(self, connection_timeout: Duration) -> Self {
45        let _ = connection_timeout;
46        self
47    }
48
49    /// Connection idle timeout
50    ///
51    /// Defaults to `60 seconds`
52    pub fn idle_timeout(mut self, idle_timeout: Duration) -> Self {
53        self.idle_timeout = idle_timeout;
54        self
55    }
56}
57
58impl Default for PoolConfig {
59    fn default() -> Self {
60        Self {
61            min_idle: 0,
62            max_size: 10,
63            idle_timeout: Duration::from_secs(60),
64        }
65    }
66}