Builder

Struct Builder 

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

Pool’s Settings

extern crate poolite;
use poolite::Builder;

/// `cargo run --example without`
fn main() {
    let pool = Builder::new()
    .min(2)
    .max(9)
    .daemon(None)  // Close daemon
    .timeout(None) // Close timeout
    .name("Worker")
    .stack_size(1024*1024*2) //2Mib
    .build()
    .unwrap();

    for i in 0..33 {
        pool.push(move || test(i));
    }

    pool.join(); //wait for the pool
    println!("{:?}", pool);
}

fn test(msg: i32) {
    println!("key: {}\tvalue: {}", msg, fib(msg));
}

fn fib(msg: i32) -> i32 {
    match msg {
        0...2 => 1,
        x => fib(x - 1) + fib(x - 2),
    }
}

Implementations§

Source§

impl Builder

Source

pub fn num_cpus() -> usize

Source

pub fn new() -> Self

Examples found in repository?
examples/builder.rs (line 6)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn name<S>(self, name: S) -> Self
where S: Debug + Into<String>,

Sets thread’s name where them in the Pool,default is None('<unnamed>').

Examples found in repository?
examples/builder.rs (line 11)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn name_get(&self) -> Option<&String>

Source

pub fn stack_size(self, size: usize) -> Self

Sets thread’s stack_size where them in the Pool,default depends on OS.

Examples found in repository?
examples/builder.rs (line 12)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn stack_size_get(&self) -> Option<&usize>

Source

pub fn min(self, min: usize) -> Self

Sets the minimum number of threads in the Pool,default is num_cpus()+1.

Examples found in repository?
examples/builder.rs (line 7)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn min_get(&self) -> &usize

Source

pub fn max(self, max: usize) -> Self

Sets the maximum number of threads in the Pool,default is (num_cpus()+1)*num_cpus().

Examples found in repository?
examples/builder.rs (line 8)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn max_get(&self) -> &usize

Source

pub fn timeout_ms(self, timeout: Option<u64>) -> Self

Sets thread’s idle time(ms) except minimum number of threads,default is 5000(ms).

Source

pub fn timeout(self, timeout: Option<Duration>) -> Self

Examples found in repository?
examples/builder.rs (line 10)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn timeout_get(&self) -> Option<&Duration>

Source

pub fn daemon_ms(self, daemon: Option<u64>) -> Self

Sets whether to open the daemon for the Pool, the default is Some(5000)(thread’s default idle time(ms)).

You can use None to close.

Source

pub fn daemon(self, daemon: Option<Duration>) -> Self

Examples found in repository?
examples/builder.rs (line 9)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}
Source

pub fn daemon_get(&self) -> Option<&Duration>

Source

pub fn load_limit(self, load_limit: usize) -> Self

Sets the value of load_limit for the Pool.

default is num_cpus() * num_cpus().

Source

pub fn load_limit_get(&self) -> &usize

Source

pub fn build(self) -> Result<Pool, PoolError>

Examples found in repository?
examples/builder.rs (line 13)
5fn main() {
6    let pool = Builder::new()
7    .min(1)
8    .max(9)
9    .daemon(None) // Close
10    .timeout(None) //Close
11    .name("Worker")
12    .stack_size(1024*1024*2) //2Mib
13    .build()
14    .unwrap();
15
16    for i in 0..38 {
17        pool.push(move || test(i));
18    }
19
20    pool.join(); //wait for the pool
21    println!("{:?}", pool);
22}

Trait Implementations§

Source§

impl Debug for Builder

Source§

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

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

impl Default for Builder

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.
Source§

impl<T> Erased for T