pub struct Reusable<T: ObjectPool> { /* private fields */ }Expand description
A wrapper for an object that will return the object to the pool when it is
dropped. This is useful for objects that are expensive to create, but are
used frequently. This struct can be created using the
Pool::remove_reusable function. However, it is highly recommended that
you use the ObjectPool::new function instead, as it will reuse objects
from the pool if possible.
The object implements Deref and DerefMut to allow you to access the
object inside the wrapper. It also implements Borrow and BorrowMut
to allow you to access the object inside the wrapper immutably or mutably.
Finally, it implements AsRef and AsMut to allow you to access the
object inside the wrapper immutably or mutably.
§Example
use derivable_object_pool::prelude::*;
#[derive(Default, ObjectPool)]
struct Test(i32);
fn test(obj: &mut Test) {
obj.0 += 1;
}
fn main() {
let mut obj = Test::new();
assert_eq!(obj.0, 0);
test(&mut obj);
assert_eq!(obj.0, 1);
}Implementations§
Source§impl<T: ObjectPool> Reusable<T>
impl<T: ObjectPool> Reusable<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the owned object inside the wrapper. This will return the object without returning it to the pool. This is useful if you want to take ownership of the object.