pub struct Pool<T> { /* private fields */ }
Expand description
A pool of objects that can be reused. This is useful for objects that are
expensive to create, but are used frequently. This struct can be created
using the Pool::new
function. However, it is highly recommended that
you use the ObjectPool
trait instead, as it is much easier to use.
§Example
Example without deriving ObjectPool
:
use derivable_object_pool::prelude::*;
#[derive(Default)]
struct Test;
static POOL: Pool<Test> = Pool::new(Test::default);
impl ObjectPool for Test {
fn pool<'a>() -> &'a Pool<Self> {
&POOL
}
}
fn main() {
let obj = Test::new();
drop(obj); // obj is returned to the pool
assert_eq!(POOL.len(), 1);
}
Implementations§
Source§impl<T> Pool<T>
impl<T> Pool<T>
Source§impl<T: ObjectPool> Pool<T>
impl<T: ObjectPool> Pool<T>
Sourcepub fn remove_reusable(&self) -> Option<Reusable<T>>
pub fn remove_reusable(&self) -> Option<Reusable<T>>
Removes an object from the pool and returns a resuable wrapper for it, which will return the object to the pool when it is dropped.
Auto Trait Implementations§
impl<T> !Freeze for Pool<T>
impl<T> RefUnwindSafe for Pool<T>
impl<T> Send for Pool<T>where
T: Send,
impl<T> Sync for Pool<T>where
T: Send,
impl<T> Unpin for Pool<T>where
T: Unpin,
impl<T> UnwindSafe for Pool<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more