[][src]Struct lock_free_freelist::Reuse

pub struct Reuse<'a, T: SmartPointer> where
    <T as Deref>::Target: Sized + Reusable
{ /* fields omitted */ }

This is a wrapper around smart pointers so that when they are dropped, raw pointers contained in them can be put to free list and reused.

This is produced by a FreeList. It is a smart pointer that contains shared ref to a FreeList instance and when the SmartPointer within it is about to drop, it takes the pointer inside of it and stores it in the free list instead.

It implements Deref and DerefMut to access the wrapped smart pointer.

Example

use lock_free_freelist::{FreeList, Reuse};

let free_list = FreeList::<Box<i32>>::new();

let reusable_box: Reuse<Box<i32>> = free_list.alloc(5);

drop(reusable_box); // So that it can be reused

let mut new_reusable_box: Reuse<Box<i32>> = free_list.reuse(9).unwrap();

assert_eq!(**new_reusable_box, 9);

Implementations

impl<'a, T: SmartPointer> Reuse<'a, T> where
    <T as Deref>::Target: Sized + Reusable
[src]

pub fn new<'b>(smart_pointer: T, free_list: &'b FreeList<T>) -> Reuse<'b, T>[src]

Get a new Reuse instance.

Trait Implementations

impl<'a, T: SmartPointer> Deref for Reuse<'a, T> where
    <T as Deref>::Target: Sized + Reusable
[src]

type Target = T

The resulting type after dereferencing.

impl<'a, T: SmartPointer> DerefMut for Reuse<'a, T> where
    <T as Deref>::Target: Sized + Reusable
[src]

impl<'a, T: SmartPointer> Drop for Reuse<'a, T> where
    <T as Deref>::Target: Sized + Reusable
[src]

When the instance of this type is dropped, an attempt is made to put the pointer of the contained SmartPointer into free list and if free list is full, the contents are dropped.

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for Reuse<'a, T>

impl<'a, T> Send for Reuse<'a, T> where
    T: Send

impl<'a, T> Sync for Reuse<'a, T> where
    T: Sync

impl<'a, T> Unpin for Reuse<'a, T> where
    T: Unpin

impl<'a, T> !UnwindSafe for Reuse<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.