pub trait PoolProvider<T: PoolItem>: Send + 'static {
type Entry: DerefMut<Target = T> + StableDeref + Send + 'static;
// Required methods
fn take<F, E>(&self, create: F) -> Result<Self::Entry, PoolError<E>>
where F: FnOnce() -> Result<T, E>;
fn return_entry(&self, entry: Self::Entry) -> Result<(), Self::Entry>;
fn warm<F, E>(&self, count: usize, create: F) -> Result<usize, PoolError<E>>
where F: FnMut() -> Result<T, E>;
}Expand description
Supplies complete take, return, and warming operations for a pool.
The provider owns all policy decisions. It may use a queue, thread-local storage, sharding, remote-return queues, or another implementation without exposing those concepts through this trait.
§Reentrancy
take and warm must invoke create without holding an
exclusive borrow or lock that would make reentrant acquisition unsound.
return_entry must return a rejected entry to its caller rather than
dropping it while such internal access remains active. Providers must keep
storage invariants valid on unwind. take and warm should use
PoolError::catch to capture unwinding panics.
Required Associated Types§
Sourcetype Entry: DerefMut<Target = T> + StableDeref + Send + 'static
type Entry: DerefMut<Target = T> + StableDeref + Send + 'static
Provider-owned entry with exclusive access to an address-stable value. Providers choose its allocation strategy and private routing context.
An entry providing access without StableDeref is insufficient:
use rylv_pool::{PoolError, PoolItem, PoolProvider};
struct Provider;
impl PoolProvider<Item> for Provider {
type Entry = InlineEntry;
}Required Methods§
Sourcefn take<F, E>(&self, create: F) -> Result<Self::Entry, PoolError<E>>
fn take<F, E>(&self, create: F) -> Result<Self::Entry, PoolError<E>>
Take a reusable entry, invoking create only on a pool miss.
§Errors
Returns the factory error or a captured panic when acquisition fails.
Sourcefn return_entry(&self, entry: Self::Entry) -> Result<(), Self::Entry>
fn return_entry(&self, entry: Self::Entry) -> Result<(), Self::Entry>
Return an entry to its pool.
On rejection, ownership must be returned so destruction happens after provider access has ended.
§Errors
Returns the unchanged entry when the provider cannot retain or route it. The guard then destroys it after provider access has ended.
Sourcefn warm<F, E>(&self, count: usize, create: F) -> Result<usize, PoolError<E>>
fn warm<F, E>(&self, count: usize, create: F) -> Result<usize, PoolError<E>>
Ensure that up to count configured values are available for reuse.
If creation fails after some entries were inserted, those entries stay available and the creation error is returned.
§Errors
Returns the factory error or a captured panic while warming the pool.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: PoolItem, const N: usize> PoolProvider<T> for &'static LocalKey<FixedThreadLocalPool<T, N>>
If storage is unavailable during thread shutdown, acquisition creates an
unpooled entry and warming does nothing. Returns reject entries so they
are destroyed outside storage access.
impl<T: PoolItem, const N: usize> PoolProvider<T> for &'static LocalKey<FixedThreadLocalPool<T, N>>
If storage is unavailable during thread shutdown, acquisition creates an unpooled entry and warming does nothing. Returns reject entries so they are destroyed outside storage access.