pub trait NativeService: Send + Sync {
// Required method
fn execute(&self, args: &JsonValue) -> IoResult;
// Provided method
fn execute_async<'a>(
&'a self,
args: &'a JsonValue,
) -> Pin<Box<dyn Future<Output = IoResult> + Send + 'a>> { ... }
}Expand description
Uniform entry point for native services: receives args (with __
paths already resolved to concrete values by the engine) and returns the
business result.
Required Methods§
Provided Methods§
Sourcefn execute_async<'a>(
&'a self,
args: &'a JsonValue,
) -> Pin<Box<dyn Future<Output = IoResult> + Send + 'a>>
fn execute_async<'a>( &'a self, args: &'a JsonValue, ) -> Pin<Box<dyn Future<Output = IoResult> + Send + 'a>>
Async extension point for native services that need external I/O (HTTP egress, long polling, and similar).
The default implementation wraps the synchronous execute in an
immediately-ready future (byte-for-byte equivalent for existing
services; invisible to the upper layer). The router uniformly awaits
execute_async, so overriders and non-overriders are fully
transparent to callers.
§Why this extension point exists
execute is synchronous: plugins previously had no regular egress
path at all. Pure-computation services are fine, but services calling
external APIs (LLM advisors and similar) had nowhere to go except
offline stubs. The async extension point brings egress into the
regular plugin mechanism without changing the core crate’s execution
semantics.
§Discipline
Services that need external I/O must override this method; they
must not perform egress from the synchronous execute (no runtime
support on that path). Any degraded result (e.g. a local stub while
the external service is unavailable) must be truthfully labeled in
the returned body; a stub must never impersonate the real service.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".