Struct ThreadPoolBuilder

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

A builder for configuring and creating a ThreadPool.

This builder allows you to set various parameters for the thread pool, such as the number of threads, stack size, and a name prefix for the threads.

§Examples

Creating a thread pool with default settings:

use base_threadpool::ThreadPoolBuilder;

let pool = ThreadPoolBuilder::default().build();

Creating a customized thread pool:

use base_threadpool::ThreadPoolBuilder;

let pool = ThreadPoolBuilder::default()
    .num_threads(4)
    .stack_size(3 * 1024 * 1024)
    .name_prefix("worker".to_string())
    .build();

Implementations§

Source§

impl ThreadPoolBuilder

Source

pub fn new( num_threads: usize, stack_size: usize, name_prefix: String, ) -> ThreadPoolBuilder

Constructs a new instance of ThreadPoolBuilder with specified parameters.

§Arguments
  • num_threads - The number of threads in the pool. Must be greater than 0.
  • stack_size - The stack size for each thread in bytes.
  • name_prefix - A prefix for naming the threads in the pool.
§Panics

Panics if num_threads is 0.

use base_threadpool::ThreadPoolBuilder;

let builder = ThreadPoolBuilder::new(4, 2 * 1024 * 1024, "custom-worker".to_string());
let pool = builder.build();
Source

pub fn build(&self) -> ThreadPool

Builds and returns a new ThreadPool instance based on the current configuration.

§Examples
use base_threadpool::ThreadPoolBuilder;

let pool = ThreadPoolBuilder::default().num_threads(2).build();
Source

pub fn num_threads(self, num_threads: usize) -> ThreadPoolBuilder

Sets the number of threads for the thread pool.

§Panics

Panics if num_threads is 0.

§Examples
use base_threadpool::ThreadPoolBuilder;

let builder = ThreadPoolBuilder::default().num_threads(8);
Source

pub fn stack_size(self, stack_size: usize) -> ThreadPoolBuilder

Sets the stack size, in bytes, for each thread in the pool.

§Examples
use base_threadpool::ThreadPoolBuilder;

let builder = ThreadPoolBuilder::default().stack_size(4 * 1024 * 1024);
Source

pub fn name_prefix(self, name_prefix: String) -> ThreadPoolBuilder

Sets the name prefix for threads in the pool.

§Examples
use base_threadpool::ThreadPoolBuilder;

let builder = ThreadPoolBuilder::default().name_prefix("my-worker".to_string());

Trait Implementations§

Source§

impl Debug for ThreadPoolBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ThreadPoolBuilder

Default parameters for ThreadPoolBuilder The Default number of threads available for the ThreadPool is std::thread::available_parallelism.

Source§

fn default() -> ThreadPoolBuilder

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.