wasmrs-guest

This crate provides the WebAssembly-side logic for wasmRS modules using the wasmRS RSocket protocol.

Usage

This is a basic implementation of a WebAssembly module that exports three operations:

```rs use guest::*; use wasmrs_guest as guest;

[no_mangle]

extern "C" fn _wasmrsinit(guestbuffersize: u32, hostbuffersize: u32, maxhostframelen: u32) { guest::init(guestbuffersize, hostbuffersize, maxhostframelen);

guest::registerrequestresponse("greeting", "sayHello", requestresponse); guest::registerrequeststream("echo", "chars", requeststream); guest::registerrequestchannel("echo", "reverse", request_channel); }

fn requestresponse(input: Mono) -> Result, GenericError> { Ok(Mono::fromfuture(async move { let input = deserialize::(&input.await.unwrap().data).unwrap(); let output = format!("Hello, {}!", input); Ok(Payload::new_data(None, Some(serialize(&output).unwrap().into()))) })) }

fn requeststream( input: Mono, ) -> Result, GenericError> { let channel = Flux::::new(); let rx = channel.takerx().unwrap(); spawn(async move { let input = deserialize::(&input.await.unwrap().data).unwrap(); for char in input.chars() { channel .send(Payload::new_data(None, Some(serialize(&char).unwrap().into()))) .unwrap(); } });

Ok(rx) } fn requestchannel( mut input: FluxReceiver, ) -> Result, GenericError> { let channel = Flux::::new(); let rx = channel.takerx().unwrap(); spawn(async move { while let Some(payload) = input.next().await { if let Err(e) = payload { println!("{}", e); continue; } let payload = payload.unwrap(); let input = deserialize::(&payload.data).unwrap(); let output: String = input.chars().rev().collect(); if let Err(e) = channel.send(Payload::new_data(None, Some(serialize(&output).unwrap().into()))) { println!("{}", e); } } });

Ok(rx) } ```

Apex Code generators

NanoBus iota code generators use the wasmRS protocol so you can build wasmRS modules from those templates using the https://github.com/apexlang/apex CLI.

Run the following command to get started:

sh $ apex new git@github.com:nanobus/iota.git -p templates/rust [your-project]

From there, edit the apex.axdl interface definition to match your needs and run apex build to generate the wasmRS module.

More Information

WasmRS makes heavy use of generated code from apex specs and generators to automate all of the boilerplate. See the getting-started for nanobus for up-to-date usage.

For more information on wasmRS, see the core wasmrs crate.

Contributing

See CONTRIBUTING.md

License

See the root LICENSE.txt