use core::time::Duration;
use crate::pool::ThreadPool;
#[derive(Clone)]
pub struct Builder {
pub(crate) min_threads: usize,
pub(crate) max_threads: Option<usize>,
pub(crate) thread_name: Option<String>,
pub(crate) thread_stack_size: Option<usize>,
pub(crate) idle_timeout: Duration,
}
impl Default for Builder {
fn default() -> Self {
Self {
min_threads: 1,
max_threads: None,
thread_name: None,
thread_stack_size: None,
idle_timeout: Duration::from_secs(60 * 5),
}
}
}
impl Builder {
pub fn max_threads(mut self, num: usize) -> Builder {
assert!(num > 0);
self.max_threads = Some(num);
self
}
pub fn min_threads(mut self, num: usize) -> Builder {
assert!(num > 0);
self.min_threads = num;
self
}
pub fn thread_name(mut self, name: impl Into<String>) -> Builder {
self.thread_name = Some(name.into());
self
}
pub fn idle_timeout(mut self, dur: Duration) -> Builder {
self.idle_timeout = dur;
self
}
pub fn build(self) -> ThreadPool {
self.into()
}
}