[−][src]Crate wascap_guest
wascap-guest
The wascap-guest
library provides WebAssembly module developers with access to a
wascap-compliant host runtime. Each guest module has a single
call handler, declared with the call_handler!
macro. Inside this call handler, the guest
module should check the type URI of the delivered command and handle the command accordingly,
returning an Event
in response.
Example
extern crate wascap_guest as guest; use guest::prelude::*; call_handler!(handle_call); pub fn handle_call(ctx: &CapabilitiesContext, cmd: &Command) -> Result<Event> { match cmd.payload { Some(ref p) => match p.type_url.as_ref() { http::TYPE_URL_HTTP_REQUEST => hello_world(ctx, p.value.as_slice()), core::TYPE_URL_HEALTH_REQUEST => Ok(Event::success()), _ => Ok(Event::bad_dispatch(&p.type_url)), }, None => Ok(http::Response::bad_request().as_event(true, None)), } } fn hello_world( ctx: &CapabilitiesContext, payload: impl Into<http::Request>) -> Result<Event> { Ok(http::Response::ok().as_event(true, None)) }
Re-exports
pub extern crate prost; |
pub extern crate wascap_codec; |
Modules
guestmem | Guest module memory management |
kv | Key-Value Store |
msg | Message Broker |
prelude | Glob imports for common guest module development |
raw | Raw capability provider interface |
Macros
call_handler |
Structs
CapabilitiesContext | The capabilities context is the gateway through which all guest modules communicate with a host runtime. A reference
to a capabilities context is passed to the call handler defined by the guest module. Individual capabilities are separated
through function calls for each capability provider, including any bound opaque |
WascapHostRuntimeInterface | The default implementation of the host runtime interface. This is the runtime interface that will be inside the Capabilities Context passed to a guest module's call handler |
Constants
HRI | The singleton Host Runtime Interface for doing real, unsafe FFI calls to the runtime host |
SOURCE_GUEST | Source ID for guest modules |
Traits
HostRuntimeInterface | A trait for a host runtime interface. This abstracts the method of invoking host calls so that the host interface can be mocked for testing |
Type Definitions
Result | Wascap Guest SDK result type |