use crate::{Config, Pool};
pub struct Builder<T: Default> {
config: Config<T>,
}
impl<T: Default> Builder<T> {
pub fn new() -> Self {
Self {
config: Config::default(),
}
}
pub fn prealloc(&mut self, prealloc: usize) -> &mut Self {
self.config.prealloc = prealloc;
self
}
pub fn capacity(&mut self, capacity: usize) -> &mut Self {
self.config.capacity = capacity;
self
}
pub fn clear_func(&mut self, func: fn(&mut T)) -> &mut Self {
self.config.clear_func = Some(func);
self
}
pub fn auto_reclaim(&mut self, enable: bool) -> &mut Self {
self.config.auto_reclaim = enable;
self
}
pub fn enable_auto_reclaim(&mut self) -> &mut Self {
self.auto_reclaim(true)
}
pub fn surpluspull_threshold_for_reclaim(&mut self, threshold: usize) -> &mut Self {
self.config.surpluspull_threshold_for_reclaim = threshold;
self
}
pub fn idle_threshold_for_surpluspull(&mut self, threshold: usize) -> &mut Self {
self.config.idle_threshold_for_surpluspull = threshold;
self
}
pub fn build(&mut self) -> Pool<T> {
let config = std::mem::take(&mut self.config);
Pool::with_config(config)
}
}