pub struct ZeroPool { /* private fields */ }Implementations§
Source§impl ZeroPool
impl ZeroPool
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new thread pool with worker count equal to available parallelism
Worker count is determined by std::thread::available_parallelism(),
falling back to 1 if unavailable. This is usually the optimal choice
for CPU-bound workloads.
§Examples
use zero_pool::ZeroPool;
let pool = ZeroPool::new();Sourcepub fn with_workers(worker_count: NonZeroUsize) -> Self
pub fn with_workers(worker_count: NonZeroUsize) -> Self
Creates a new thread pool with the specified number of workers
Use this when you need precise control over the worker count, for example when coordinating with other thread pools or when you know the optimal count for your specific workload.
§Examples
use std::num::NonZeroUsize;
use zero_pool::ZeroPool;
let pool = ZeroPool::with_workers(NonZeroUsize::new(4).unwrap());Sourcepub fn submit_task<T>(&self, task_fn: fn(&T), params: &T) -> TaskFuture
pub fn submit_task<T>(&self, task_fn: fn(&T), params: &T) -> TaskFuture
Submit a single typed task
The parameter struct must remain valid until the future completes. This is the recommended method for submitting individual tasks.
§Examples
use zero_pool::ZeroPool;
struct MyTaskParams { value: u64, result: *mut u64 }
fn my_task_fn(params: &MyTaskParams) {
unsafe { *params.result = params.value * 2; }
}
let pool = ZeroPool::new();
let mut result = 0u64;
let task_params = MyTaskParams { value: 42, result: &mut result };
let future = pool.submit_task(my_task_fn, &task_params);
future.wait();
assert_eq!(result, 84);Sourcepub fn submit_batch<T>(&self, task_fn: fn(&T), params_vec: &[T]) -> TaskFuture
pub fn submit_batch<T>(&self, task_fn: fn(&T), params_vec: &[T]) -> TaskFuture
Submit a batch of uniform tasks
All tasks in the batch must be the same type and use the same task function. This method handles the pointer conversion automatically and is the most convenient way to submit large batches of similar work.
§Examples
use zero_pool::ZeroPool;
struct MyTaskParams { value: u64, result: *mut u64 }
fn my_task_fn(params: &MyTaskParams) {
unsafe { *params.result = params.value * 2; }
}
let pool = ZeroPool::new();
let mut results = vec![0u64; 1000];
let task_params: Vec<_> = (0..1000)
.map(|i| MyTaskParams { value: i as u64, result: &mut results[i] })
.collect();
let future = pool.submit_batch(my_task_fn, &task_params);
future.wait();
assert_eq!(results[0], 0);
assert_eq!(results[1], 2);
assert_eq!(results[999], 1998);