RcPool

Struct RcPool 

Source
pub struct RcPool<T: Sized>(/* private fields */);
Expand description

A single thread, interior mutable memory Pool backed by a reference count. This allows objects to hold references back to the pool to keep it alive without carrying a lifetime.

Implementations§

Source§

impl<T> RcPool<T>

Source

pub fn new() -> Self

Creates a new RcPool for objects of type T.

Trait Implementations§

Source§

impl<T> AsRef<RcPool<RcInner<T>>> for Rc<T>

Get a reference to the pool this Rc was constructed from.

Source§

fn as_ref(&self) -> &RcPool<RcInner<T>>

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

impl<T> AsRef<RcPool<ScInner<T>>> for Sc<T>

Get a reference to the pool this Sc was constructed from.

Source§

fn as_ref(&self) -> &RcPool<ScInner<T>>

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

impl<T> AsRef<RcPool<T>> for Box<T>

Get a reference to the pool this Box was constructed from.

Source§

fn as_ref(&self) -> &RcPool<T>

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

impl<T> AsRef<RcPool<T>> for RcPool<T>

Source§

fn as_ref(&self) -> &Self

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

impl<T> Clone for RcPool<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Default for RcPool<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> PoolApi<T> for RcPool<T>

Source§

fn with_min_entries(&self, min_entries: usize)

Configures the minimum of entries the first block will hold. Must be called before the first allocation is made. Can be used when the number of entries that will be used is roughly guessable and or the size of entries is small. Setting this improves cache locality. Since blocks are allocated with exponentially growing size this should be still small enough, approx 1/4 of the average number of entries to be expected. The implementation will generously round this up to the next power of two. When not set it defaults to 64 entries. Read more
Source§

fn leak(self)

Destroys a Pool while leaking its allocated blocks. The fast way out when one knows that allocations still exist and will never be returned to to the Pool. Either because the program exits or because the allocations are meant to stay.
Source§

fn alloc_entry(&self) -> NonNull<Entry<T>>

Allocates a new entry, either from the freelist or by extending the pool. Returns Entry pointer tagged as UNINITIALIZED.
Source§

fn alloc(&self, t: T) -> Slot<T, Initialized>

Allocates a new slot from the pool, initializes it with the supplied object and returns a slot handle. Freeing the object should be done manually with pool.free(), pool::forget() or pool.take(). The user must take care that the slot/references obtained from it are not used after free as this may panic or return another object.
Source§

unsafe fn free_by_ref<S: DropPolicy>(&self, slot: &mut Slot<T, S>)

Non consuming variant of pool.free(), allows freeing slots that are part of other structures while keeping Slot non-Copy. The slot must not be used after this. See slot.free() for details.
Source§

unsafe fn take_by_ref<S: CanTakeValue>(&self, slot: &mut Slot<T, S>) -> T

Non consuming variant of pool.take(), allows taking slots that are part of other structures while keeping Slot non-Copy. The slot must not be used after this. See slot.take() for details.
Source§

fn alloc_uninit(&self) -> Slot<T, Uninitialized>

Allocates a new slot from the pool, keeps the content uninitialized returns a Slot handle to it. Freeing the object should be done manually with pool.free() or pool.forget(). The user must take care that the provided handle or references obtained from is are used after free as this may panic or return another object.
Source§

unsafe fn free<S: DropPolicy>(&self, slot: Slot<T, S>)

Frees slot by calling its destructor when it contains an initialized object, uninitialized objects become forgotten as with Pool::forget(). Puts the given slot back into the freelist. Read more
Source§

unsafe fn forget<S: Policy>(&self, slot: Slot<T, S>)

Puts the given slot back into the freelist. Will not call the the destructor. Read more
Source§

unsafe fn forget_by_ref<S: Policy>(&self, slot: &mut Slot<T, S>)

Non consuming variant of pool.forget(), allows forgetting slots that are part of other structures while keeping Slot non-Copy. The slot must not be used after this. See slot.forget() for details.
Source§

unsafe fn take<S: CanTakeValue>(&self, slot: Slot<T, S>) -> T

Takes an object out of the Pool and returns it. The slot at slot is put back to the freelist. This operation violates the Pin guarantees, thus in presence of pinned operation it must not be used. Read more

Auto Trait Implementations§

§

impl<T> Freeze for RcPool<T>

§

impl<T> !RefUnwindSafe for RcPool<T>

§

impl<T> !Send for RcPool<T>

§

impl<T> !Sync for RcPool<T>

§

impl<T> Unpin for RcPool<T>

§

impl<T> !UnwindSafe for RcPool<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.