deadpool/unmanaged/
config.rs

1use std::time::Duration;
2
3use crate::Runtime;
4
5/// Pool configuration.
6#[derive(Clone, Copy, Debug)]
7#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8pub struct PoolConfig {
9    /// Maximum size of the pool.
10    pub max_size: usize,
11
12    /// Timeout for [`Pool::get()`] operation.
13    ///
14    /// [`Pool::get()`]: super::Pool::get
15    pub timeout: Option<Duration>,
16
17    /// [`Runtime`] to be used.
18    #[cfg_attr(feature = "serde", serde(skip))]
19    pub runtime: Option<Runtime>,
20}
21
22impl PoolConfig {
23    /// Create a new [`PoolConfig`] without any timeouts.
24    #[must_use]
25    pub fn new(max_size: usize) -> Self {
26        Self {
27            max_size,
28            timeout: None,
29            runtime: None,
30        }
31    }
32}
33
34impl Default for PoolConfig {
35    /// Create a [`PoolConfig`] where [`PoolConfig::max_size`] is set to
36    /// `cpu_core_count * 2` including logical cores (Hyper-Threading).
37    fn default() -> Self {
38        Self::new(crate::util::get_default_pool_max_size())
39    }
40}