Crate wapc_guest

Crate wapc_guest 

Source
Expand description

§waPC Guest SDK

crates.io license

The wapc-guest library is an implementation of the guest-side of the waPC WebAssembly protocol. wapc-guest gives Rust developers the pieces necessary to easily compile WebAssembly modules that you can load in waPC hosts. Each guest module registers function handlers with register_function(). Each handler should return a CallResult (a Result<Vec<u8>,Box<dyn Error + Sync + Send>>) with the function’s return value.

It’s typically used by code generated by the wapc CLI.

§Example

use wapc_guest as wapc;

#[no_mangle]
pub fn wapc_init() {
  wapc::register_function("ping", ping);
}

fn ping(msg: &[u8]) -> wapc::CallResult {
  wapc::console_log(&format!(
    "IN_WASM: Received request for `ping` operation with payload : {}",
    std::str::from_utf8(msg).unwrap()
  ));
  let _res = wapc::host_call("binding", "sample:namespace", "pong", msg)?;
  Ok(msg.to_vec())
}

§Building

This crate is meant for projects targeting wasm32-unknown-unknown or wasm32-wasip1.

Modules§

errors
Errors
prelude
Glob imports for common guest module development

Functions§

__guest_call
The __guest_call function is required by waPC guests and should only be called by waPC hosts.
console_log
Log function that delegates to the host’s __console_log function
host_call
The function through which all host calls take place.
register_function
Register a handler for a waPC operation

Type Aliases§

CallResult
CallResult is the result for all waPC host and guest calls.
HandlerResult
A generic type for the result of waPC operation handlers.