Struct ThreadPoolBuilder

Source
pub struct ThreadPoolBuilder { /* private fields */ }
Expand description

A ThreadPoolbuilder is a builder to easily create a thread pool

Implementations§

Source§

impl ThreadPoolBuilder

Source

pub fn with_thread_amount(thread_amount: NonZeroUsize) -> ThreadPoolBuilder

Initialize the amount of threads the builder will build to thread_amount

Source

pub fn with_thread_amount_usize( thread_amount: usize, ) -> Result<ThreadPoolBuilder, TryFromIntError>

Initialize the amount of threads the builder will build to thread_amount.

§Errors

If thread_amount cannot be converted to a std::num::NonZeroUsize (aka it is 0).

Source

pub fn with_max_threads() -> Result<ThreadPoolBuilder>

Initialize the amount of threads the builder will build to the available parallelism as provided by std::thread::available_parallelism

§Errors

Taken from the available_parallelism() documentation: This function will, but is not limited to, return errors in the following cases:

  • If the amount of parallelism is not known for the target platform.
  • If the program lacks permission to query the amount of parallelism made available to it.
Source

pub fn set_thread_amount(self, thread_amount: NonZeroUsize) -> ThreadPoolBuilder

Set the thead amount in the builder

Source

pub fn set_thread_amount_usize( self, thread_amount: usize, ) -> Result<ThreadPoolBuilder, TryFromIntError>

Set the thead amount in the builder from usize

§Errors

If thread_amount cannot be turned into NonZeroUsize (aka it is 0)

Source

pub fn set_max_threads(self) -> Result<ThreadPoolBuilder>

set the amount of threads the builder will build to the available parallelism as provided by std::thread::available_parallelism

§Errors

Taken from the available_parallelism() documentation: This function will, but is not limited to, return errors in the following cases:

  • If the amount of parallelism is not known for the target platform.
  • If the program lacks permission to query the amount of parallelism made available to it.
Source

pub fn build(self) -> Result<ThreadPool>

Build the builder into a threadpool, taking all the initialized values from the builder and using defaults for those not initialized.

§Errors

Taken from std::thread::Builder::spawn:

Unlike the spawn free function, this method yields an io::Result to capture any failure to create the thread at the OS level.

Trait Implementations§

Source§

impl Default for ThreadPoolBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.