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 pool of pre-warmed instances for one plugin.

Generic over the pooled instance type T and the loader’s error type E. Production use: InstancePool<extism::Plugin, ExtismError> or InstancePool<wasmtime::component::Instance, WasmError>.

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 new instances via factory.

Eagerly constructs cfg.warm_count.min(cfg.max_instances) instances at construction time so first-call latency is the pool’s steady-state hit cost, not a fresh wasmtime compile.

§Errors

Propagates factory errors from initial warm-up.

Source

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

Acquire an instance from the pool.

Pops a warm instance if available; otherwise constructs a new one if live < max_instances. Returns a loader-specific resource-limit error if the pool is at capacity.

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

pub fn release(&self, inst: T)

Release an instance back to the pool.

On overflow (race with reaper), the instance is dropped — its Drop impl is responsible for any cleanup.

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.