Skip to main content

InstancePool

Struct InstancePool 

Source
pub struct InstancePool<T, E>
where T: Send + 'static, E: PoolResourceLimit + Send + Sync + 'static,
{ /* private fields */ }
Expand description

A per-plugin instance cache with a concurrency cap.

Generic over the per-invoke instance type T and the loader’s error type E. Production use: InstancePool<extism::Plugin, ExtismError> or InstancePool<ScalarPluginInstance, WasmError>.

Does not reuse instances — every Self::acquire builds a fresh one and every release drops it. See the module docs for why.

Implementations§

Source§

impl<T, E> InstancePool<T, E>
where T: Send + 'static, E: PoolResourceLimit + Send + Sync + 'static,

Source

pub fn new( cfg: PoolConfig, factory: impl Fn() -> Result<T, E> + Send + Sync + 'static, ) -> Result<Self, E>

Construct a pool that builds fresh instances via factory.

cfg.warm_count is accepted for API compatibility but ignored: nothing is pre-warmed, because instances are never reused.

§Errors

This constructor is infallible in practice; the E in the return type is retained so the signature is stable across the refactor.

Source

pub fn acquire(&self) -> Result<T, E>

Acquire a fresh instance, honoring the concurrency cap.

Reserves a live slot (CAS against max_instances), then builds a brand-new instance via the factory. No warm reuse — the returned instance has clean state. Releasing it (via PooledInstance’s drop) frees the slot.

§Errors
  • E::resource_limit(...) when max_instances is reached.
  • Whatever the factory returns on construction failure.
Source

pub fn release(&self, inst: T)

Release an instance, freeing its concurrency slot.

The instance is dropped here (never recycled), so its Drop impl runs any cleanup. A trapped instance is therefore discarded, not handed back out.

Source

pub fn metrics(&self) -> Arc<PoolMetrics>

Snapshot the current metrics.

Source

pub fn config(&self) -> &PoolConfig

Pool configuration, for diagnostics.

Trait Implementations§

Source§

impl<T, E> Debug for InstancePool<T, E>
where T: Send + 'static, E: PoolResourceLimit + Send + Sync + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, E> !Freeze for InstancePool<T, E>

§

impl<T, E> !RefUnwindSafe for InstancePool<T, E>

§

impl<T, E> !UnwindSafe for InstancePool<T, E>

§

impl<T, E> Send for InstancePool<T, E>

§

impl<T, E> Sync for InstancePool<T, E>

§

impl<T, E> Unpin for InstancePool<T, E>

§

impl<T, E> UnsafeUnpin for InstancePool<T, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.