[][src]Crate wasi_worker_yew

Yew worker compilable to wasm32-wasi target. It allows to compile and run POSIX-like applications, having access to random and to emulated file system (memfs). On some operations wasi workers run faster than wasm-bindgen or stdweb.

It depends on wasi-worker-cli for deployment.

Example usage:

use wasi_worker_yew::{ThreadedWASI, WASIAgent};
use yew::agent::*;
use wasi_worker::{FileOptions, ServiceOptions, ServiceWorker};

pub struct MyAgent;
impl Agent for MyAgent {
    type Reach = Public;
    type Message = String;
    type Input = String;
    type Output = String;
    fn create(_link: AgentLink<Self>) -> Self { MyAgent { } }
    fn update(&mut self, _msg: Self::Message) { /* ... */ }
    fn handle(&mut self, _msg: Self::Input, _who: HandlerId) { /* */ }
    // link to the JavaScript runner, worker instantiated from:
    fn name_of_resource() -> &'static str { "worker.js" }
};

// In usual WASI setup with JS glue all output will be posted to /output.bin
// Though in user filesystem output goes under ./output.bin
let opt = ServiceOptions::default().with_cleanup();
let output_file = match &opt.output { FileOptions::File(path) => path.clone() };
ServiceWorker::initialize(opt)
  .expect("ServiceWorker::initialize");
ServiceWorker::set_message_handler(Box::new(WASIAgent::<MyAgent>::new()));

Structs

AgentLink

Link to agent's scope for creating callbacks.

HandlerId

Id of responses handler.

Public

Create a single instance in a tab.

ServiceOptions

Options for ServiceWorker

ServiceWorker

Connects Rust Handler with browser service worker via WASI filesystem.

WASIAgent

WASIAgent is the main executor and communication bridge for yew Agent with Reach = Public

Enums

FileOptions

Instructs on file descriptor configuration for ServiceWorker

FromWorker

Serializable messages sent by worker to consumer

ToWorker

Serializable messages to worker

Traits

Agent

Declares the behavior of the agent.

Packed

Message packager, based on serde::Serialize/Deserialize

ThreadedWASI

Implements rules to register a worker in a separate thread.