LendPool
LendPool is a simple lock-free library for allowing safe and concurrent access to a group of objects.
It achieves this with a Loan<T> guard.
Example Usage
use lendpool::LendPool;
fn main() {
let pool = LendPool::new();
pool.add("Resource 1".to_string());
pool.add("Resource 2".to_string());
if let Some(loan) = pool.loan() {
println!("Borrowed item: {}", *loan);
loan.with_mut(|val| val.push_str(" - Modified"));
println!("Modified item: {}", *loan);
};
if let Some(mut loan) = pool.loan() {
let item = loan.take();
println!("Took item: {}", item);
};
println!("Available items: {}", pool.available());
println!("Items on loan: {}", pool.on_loan());
println!("Total items: {}", pool.total());
}
Feature Flags
- sync: allows blocking until a resource is available
- async: allows waiting on the pool until a resource is available
Dependencies
LendPool is based on crossbeam_queue::SegQueue.
The async feature uses tokio::sync::Notify to handle waiting.