pub struct ThreadPoolBuilder { /* private fields */ }
Expand description
A ThreadPoolbuilder is a builder to easily create a thread pool
Implementations§
Source§impl ThreadPoolBuilder
impl ThreadPoolBuilder
Sourcepub fn with_thread_amount(thread_amount: NonZeroUsize) -> ThreadPoolBuilder
pub fn with_thread_amount(thread_amount: NonZeroUsize) -> ThreadPoolBuilder
Initialize the amount of threads the builder will build to thread_amount
Sourcepub fn with_thread_amount_usize(
thread_amount: usize,
) -> Result<ThreadPoolBuilder, TryFromIntError>
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).
Sourcepub fn with_max_threads() -> Result<ThreadPoolBuilder>
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.
Sourcepub fn set_thread_amount(self, thread_amount: NonZeroUsize) -> ThreadPoolBuilder
pub fn set_thread_amount(self, thread_amount: NonZeroUsize) -> ThreadPoolBuilder
Set the thead amount in the builder
Sourcepub fn set_thread_amount_usize(
self,
thread_amount: usize,
) -> Result<ThreadPoolBuilder, TryFromIntError>
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)
Sourcepub fn set_max_threads(self) -> Result<ThreadPoolBuilder>
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.
Sourcepub fn build(self) -> Result<ThreadPool>
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.