Derivable Object Pool
This crate provides a trait that can be derived to implement an object pool
for a type with a single line of code. Allowing the user to forget about
the implementation details of the ObjectPool
and focus on the important parts of their code
This crate has the following features compared to other object pool crates:
- Derivable: The pool is simple to use and can be used with any type. Can
be just derived using the
#[derive(ObjectPool)]attribute macro. - Reusable: The user can use the
ObjectPool::newfunction to create objects from the pool, which will reuse objects from the pool if possible. This items are wrapped in aReusablestruct, which will be returned to the pool when dropped. - Thread Safe: The pool is thread-safe (through the use of a
Mutex) and can be used in a multi-threaded environment. - Simple: The user doesn't need to create a pool for each type manually
and can use the
ObjectPool::newfunction to create objects from the pool. - Flexible: The user can configure the pool to use a custom generator
function (see attributes in
#[derive(ObjectPool)]) or just use theDefaulttrait to create new objects.
Installation
Add the following to your Cargo.toml file:
[]
= "0.1.1"
Usage
Without specifying any attributes, the pool will use the Default trait to create new objects:
use *;
;
Or you can specify a custom generator function using the #[generator] attribute:
use *;
;
Documentation
The documentation can be found here.
License
This project is licensed under the dual MIT/Apache-2.0 license. For more information, see LICENSE-APACHE and LICENSE-MIT.