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>
impl<T: PoolItem, P: PoolProvider<T>> PoolGuard<T, P>
Sourcepub fn acquire(provider: P) -> Result<Self, PoolError<Infallible>>where
T: Default,
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.
Sourcepub fn acquire_with<F>(
provider: P,
create: F,
) -> Result<Self, PoolError<Infallible>>where
F: FnOnce() -> T,
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.
Trait Implementations§
impl<T: PoolItem, P: PoolProvider<T>> StableDeref for PoolGuard<T, P>
Auto Trait Implementations§
impl<T, P> Freeze for PoolGuard<T, P>
impl<T, P> RefUnwindSafe for PoolGuard<T, P>
impl<T, P> Send for PoolGuard<T, P>
impl<T, P> Sync for PoolGuard<T, P>
impl<T, P> Unpin for PoolGuard<T, P>
impl<T, P> UnsafeUnpin for PoolGuard<T, P>
impl<T, P> UnwindSafe for PoolGuard<T, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more