Skip to main content

PoolGuard

Struct PoolGuard 

Source
pub struct PoolGuard<T: PoolItem, P: PoolProvider<T>> { /* private fields */ }
Expand description

Exclusive, address-stable guard returned by a PoolProvider.

§Address stability

The provider entry implements StableDeref, keeping the value at the same address for the complete lifetime of the guard, even when the guard moves.

References into the value cannot outlive the guard:

ⓘ
use rylv_pool::{FixedThreadLocalPool, FixedThreadLocalPoolGuard, PoolItem};
let mut guard = FixedThreadLocalPoolGuard::acquire(&POOL).unwrap();
let borrowed = &mut guard.0;
drop(guard);
borrowed.push(1);

A guard cannot provide two simultaneously used mutable references:

ⓘ
use rylv_pool::{FixedThreadLocalPool, FixedThreadLocalPoolGuard, PoolItem};
let mut guard = FixedThreadLocalPoolGuard::acquire(&POOL).unwrap();
let first = &mut guard.0;
let second = &mut guard.0;
first.push(1);
second.push(2);

A guard cannot be cloned to create a second owner:

ⓘ
use rylv_pool::{FixedThreadLocalPool, FixedThreadLocalPoolGuard, PoolItem};
let guard = FixedThreadLocalPoolGuard::acquire(&POOL).unwrap();
let duplicate = guard.clone();

Implementations§

Source§

impl<T: PoolItem, P: PoolProvider<T>> PoolGuard<T, P>

Source

pub fn acquire(provider: P) -> Result<Self, PoolError<Infallible>>
where T: Default,

Acquire a value through the supplied provider.

§Errors

Returns a captured panic if acquisition or the default factory unwinds.

Source

pub fn acquire_with<F>( provider: P, create: F, ) -> Result<Self, PoolError<Infallible>>
where F: FnOnce() -> T,

Acquire a value, using create only when the provider misses.

§Errors

Returns a captured panic if acquisition or the factory unwinds.

Source

pub fn try_acquire_with<F, E>( provider: P, create: F, ) -> Result<Self, PoolError<E>>
where F: FnOnce() -> Result<T, E>,

Acquire a value using a fallible factory only when the provider misses.

§Errors

Returns the factory error or a captured panic without creating a guard.

Trait Implementations§

Source§

impl<T: PoolItem, P: PoolProvider<T>> Deref for PoolGuard<T, P>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: PoolItem, P: PoolProvider<T>> DerefMut for PoolGuard<T, P>

Source§

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

Mutably dereferences the value.
Source§

impl<T: PoolItem, P: PoolProvider<T>> Drop for PoolGuard<T, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: PoolItem, P: PoolProvider<T>> StableDeref for PoolGuard<T, P>

Auto Trait Implementations§

§

impl<T, P> Freeze for PoolGuard<T, P>
where ManuallyDrop<<P as PoolProvider<T>>::Entry>: Freeze, P: Freeze,

§

impl<T, P> RefUnwindSafe for PoolGuard<T, P>

§

impl<T, P> Send for PoolGuard<T, P>
where ManuallyDrop<<P as PoolProvider<T>>::Entry>: Send,

§

impl<T, P> Sync for PoolGuard<T, P>
where ManuallyDrop<<P as PoolProvider<T>>::Entry>: Sync, P: Sync,

§

impl<T, P> Unpin for PoolGuard<T, P>
where ManuallyDrop<<P as PoolProvider<T>>::Entry>: Unpin, P: Unpin,

§

impl<T, P> UnsafeUnpin for PoolGuard<T, P>

§

impl<T, P> UnwindSafe for PoolGuard<T, P>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.