piscina

A simple generic pool that supports both sync and async.

crate<em>version docs</em>version

This crate provides a simple generic pool that uses channels instead of locks and supports both sync and async without dependence on any runtime.

Features

toml default = []

The features below are related to logging errors, which should be unreachable.

Examples

Non-async example:

```rust use piscina::Pool;

let mut pool = Pool::new(); pool.put(1); pool.put(2);

let item1 = pool.tryget(); assert!(item1.issome());

let item2 = pool.blocking_get();

let none = pool.tryget(); assert!(none.isnone());

drop(item1); let item3 = pool.tryget(); assert!(item3.issome()); ```

Async example:

```rust use piscina::Pool;

futures::executor::block_on(async { let mut pool = Pool::new(); pool.put(1); pool.put(2);

let item1 = pool.get().await;
let item2 = pool.get().await;

let none = pool.try_get();
assert!(none.is_none());

drop(item1);
let item3 = pool.get().await;

}); ```

Safety

Instead of using an Option, this crate uses unsafe code ManuallyDrop in PooledItem. And the only use of unsafe code ManuallyDrop::take() occurs when PooledItem is dropped.

TODO:

License: MIT/Apache-2.0