Skip to main content

wasm_capability_contract/component/traits/
capability_engine.rs

1//! [`CapabilityEngine`] — loads and invokes a validated Wasm component's handler export.
2
3use futures::future::BoxFuture;
4
5use crate::{
6    CapabilityError, ComponentInvokeRequest, ComponentInvokeResponse, ComponentLoadRequest,
7    ComponentLoadResponse,
8};
9
10/// Loads a validated component and invokes its handler export.
11///
12/// Implementations own instantiation, isolation, and resource-limit
13/// enforcement — none of that is expressed in this trait, matching every
14/// other port in this crate (the contract is the behavior, not the
15/// mechanism). Callers must have already validated the same manifest/
16/// bytes against ADR-001's own two-gate contract first — `load` is not
17/// required to re-run the manifest-level grant check, only to fail if the
18/// bytes cannot actually be instantiated. Zero implementation here.
19pub trait CapabilityEngine: Send + Sync {
20    /// Load a component artifact, returning a handle for subsequent
21    /// [`CapabilityEngine::invoke`] calls.
22    ///
23    /// # Errors
24    ///
25    /// Returns [`CapabilityError`] if the bytes cannot be instantiated, or
26    /// a declared-and-granted capability has no real dispatcher wired for
27    /// it ([`CapabilityError::CapabilityUnavailable`]).
28    fn load(
29        &self,
30        req: ComponentLoadRequest,
31    ) -> BoxFuture<'_, Result<ComponentLoadResponse, CapabilityError>>;
32
33    /// Invoke a previously loaded component's handler export once.
34    ///
35    /// # Errors
36    ///
37    /// Returns [`CapabilityError`] if the component traps, exceeds a
38    /// configured resource limit, or exceeds `req.deadline`.
39    fn invoke(
40        &self,
41        req: ComponentInvokeRequest,
42    ) -> BoxFuture<'_, Result<ComponentInvokeResponse, CapabilityError>>;
43}