Crates.io | invoke-witc |
lib.rs | invoke-witc |
version | 0.3.1 |
source | src |
created_at | 2023-03-05 22:21:17.425 |
updated_at | 2023-05-17 07:20:57.492013 |
description | rust macros invokes witc |
homepage | |
repository | |
max_upload_size | |
id | 801796 |
size | 5,018 |
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
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
.
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()?)?