wasm_capability_contract/capability/traits/capability_dispatcher.rs
1//! [`CapabilityDispatcher`] — executes one granted capability call.
2
3/// Executes one capability call: decode `payload`, call the real
4/// implementor injected behind this dispatcher, encode the result back to
5/// bytes. A leaf operation (ADR-001) — never triggers a second capability
6/// call on the guest's behalf.
7///
8/// `target` names what to call within this dispatcher's own bound scope
9/// (a `"pkg.Service/Method"` for `grpc-egress`, a query name for
10/// `database`, a secret name for `secrets`, ...) — never an open-ended
11/// address the dispatcher itself resolves.
12///
13/// Returns a plain `String` error, not a typed one: every dispatcher
14/// wraps a different real implementor's own error type, and this port has
15/// no reason to unify them into one enum. Zero implementation here.
16pub trait CapabilityDispatcher: Send + Sync {
17 /// Dispatch one call to `target` with `payload`, returning the raw
18 /// response bytes.
19 ///
20 /// `tokio_handle` lets an implementor whose real call is async re-enter
21 /// a tokio runtime from a context (e.g. a component's own dedicated OS
22 /// thread) that has none of its own ambiently.
23 ///
24 /// # Errors
25 ///
26 /// Returns a human-readable message naming what failed.
27 fn dispatch(
28 &self,
29 tokio_handle: &tokio::runtime::Handle,
30 target: &str,
31 payload: Vec<u8>,
32 ) -> Result<Vec<u8>, String>;
33}