Trait AsWorkerPool

Source
pub trait AsWorkerPool<W>: From<Vec<W>> + Into<Vec<W>> {
    // Required methods
    fn new() -> Self;
    fn with_len(len: usize) -> Self;
    fn len(&self) -> usize;
    fn append(&mut self, worker: W);

    // Provided methods
    fn with_all_cpus() -> Self { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

Common interface for worker pool implementations.

Required Methods§

Source

fn new() -> Self

Creates an empty worker pool.

§Examples
use my_ecs::prelude::*;

let pool = WorkerPool::new();
assert!(pool.is_empty());
Source

fn with_len(len: usize) -> Self

Creates worker pool with len workers.

§Examples
use my_ecs::prelude::*;

let pool = WorkerPool::with_len(1);
assert_eq!(pool.len() , 1);
Source

fn len(&self) -> usize

Returns number of workers in the worker pool.

Source

fn append(&mut self, worker: W)

Appends a worker in the worker pool.

§Examples
use my_ecs::prelude::*;

let mut pool = WorkerPool::new();
assert!(pool.is_empty());

let worker = WorkerBuilder::new("name").spawn().unwrap();
pool.append(worker);
assert_eq!(pool.len(), 1);

Provided Methods§

Source

fn with_all_cpus() -> Self

Creates worker pool with workers as many as number of available logical cpus.

Number of logical cpus depends on platform which this crate runs on. This method guarantees the returned worker pool to have at least one worker in it even if it failed to get the number of logical cpus.

§Examples
use my_ecs::prelude::*;

let pool = WorkerPool::with_all_cpus();
assert!(!pool.is_empty());
Source

fn is_empty(&self) -> bool

Returns true if the worker pool doesn’t contain any workers in it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§