Builder

Struct Builder 

Source
pub struct Builder<T: Default> { /* private fields */ }
Expand description

A builder for creating a Pool with custom configuration.

§Example

use concurrent_pool::Builder;

let mut builder = Builder::<usize>::new();
let pool = builder.capacity(10).prealloc(5).build();
assert_eq!(pool.capacity(), 10);

Implementations§

Source§

impl<T: Default> Builder<T>

Source

pub fn new() -> Self

Create a new builder with default configuration.

Source

pub fn prealloc(&mut self, prealloc: usize) -> &mut Self

Set the number of preallocated items in the pool.

Source

pub fn capacity(&mut self, capacity: usize) -> &mut Self

Set the maximum capacity of the pool.

Source

pub fn clear_func(&mut self, func: fn(&mut T)) -> &mut Self

Set the function to clear an item before it is returned to the pool.

Source

pub fn auto_reclaim(&mut self, enable: bool) -> &mut Self

Enable or disable auto reclaiming allocated items and free them to reduce memory usage.

Source

pub fn enable_auto_reclaim(&mut self) -> &mut Self

Enable auto reclaiming allocated items and free them to reduce memory usage.

Source

pub fn fastpull_threshold_for_reclaim(&mut self, threshold: usize) -> &mut Self

Set the threshold of fast-pull continuous occurrence to trigger reclamation when auto_reclaim is enabled.

Source

pub fn idle_threshold_for_fastpull(&mut self, threshold: usize) -> &mut Self

Set the threshold for idle items to judge as a fast-pull when auto_reclaim is enabled.

Source

pub fn build(&mut self) -> Pool<T>

Build the pool with the current configuration.

Auto Trait Implementations§

§

impl<T> Freeze for Builder<T>

§

impl<T> RefUnwindSafe for Builder<T>

§

impl<T> Send for Builder<T>

§

impl<T> Sync for Builder<T>

§

impl<T> Unpin for Builder<T>

§

impl<T> UnwindSafe for Builder<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.