Reusable

Struct Reusable 

Source
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>

Source

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.

Trait Implementations§

Source§

impl<T: ObjectPool> AsMut<T> for Reusable<T>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ObjectPool> AsRef<T> for Reusable<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ObjectPool> Borrow<T> for Reusable<T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ObjectPool> BorrowMut<T> for Reusable<T>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T: ObjectPool> Deref for Reusable<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ObjectPool> DerefMut for Reusable<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ObjectPool> Drop for Reusable<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: ObjectPool> From<T> for Reusable<T>

Source§

fn from(item: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for Reusable<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Reusable<T>
where T: RefUnwindSafe,

§

impl<T> Send for Reusable<T>
where T: Send,

§

impl<T> Sync for Reusable<T>
where T: Sync,

§

impl<T> Unpin for Reusable<T>
where T: Unpin,

§

impl<T> UnwindSafe for Reusable<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.