invoke-witc

Crates.ioinvoke-witc
lib.rsinvoke-witc
version0.3.1
sourcesrc
created_at2023-03-05 22:21:17.425
updated_at2023-05-17 07:20:57.492013
descriptionrust macros invokes witc
homepage
repository
max_upload_size
id801796
size5,018
Lîm Tsú-thuàn (dannypsnl)

documentation

README

invoke-witc

Add the crate to the dependencies.

invoke-witc = "0.2"

The usage of this crate is using the following macros to generate polyfill programs. e.g.

invoke_witc::wit_instance!(import("./xxx.wit"));
invoke_witc::wit_runtime!(import("./xxx.wit"));
invoke_witc::wit_runtime!(export("./xxx.wit"));

Let's assume there has a file xxx.wit contains

num : func(a: u32) -> u32

and discuss some special cases

import: instance vs runtime

In instance, if we write

invoke_witc::wit_instance!(import("./xxx.wit"));

then we can just use num(10) to get a u32. But in runtime, due to the limitation, we will have to write

let u = num(&vm, 10);

where vm : Vm.

export in runtime: with & without name

Let's say we are exporting component xxx in runtime, we will need to provide definition of num, like the following.

invoke_witc::wit_runtime!(export("./xxx.wit"));

// An example implementation
fn num(a: u32) -> u32 { a + 1 }

Then we have to register import object to vm : Vm, therefore, we will write

vm.register_import_module(xxx::wit_import_object()?)?

to ensure later wasm instances can use this implementation. A notable thing is that you can define export name:

invoke_witc::wit_runtime!(export(a = "./xxx.wit"));
invoke_witc::wit_runtime!(export(b = "./yyy.wit"));

with export name, the wit_import_object will be wrapped under different module, and hence, we will have:

vm.register_import_module(a::wit_import_object()?)?
  .register_import_module(b::wit_import_object()?)?
Commit count: 0

cargo fmt