1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
pub use wasmtime::*;

pub async fn new_module_async(engine: &Engine, bytes: impl AsRef<[u8]>) -> Result<Module> {
    Module::new(engine, bytes)
}

pub async fn new_instance_async(
    store: impl AsContextMut,
    module: &Module,
    imports: &[Extern],
) -> Result<Instance> {
    Instance::new(store, module, imports)
}

pub async fn instantiate_async<T>(
    store: impl AsContextMut<Data = T>,
    linker: &Linker<T>,
    module: &Module,
) -> Result<Instance> {
    linker.instantiate(store, module)
}

#[cfg(feature = "component-model")]
pub mod component {
    pub use wasmtime::component::*;

    pub use wasm_bridge_macros::bindgen_sys as bindgen;
    pub use wasm_bridge_macros::flags_sys as flags;
    pub use wasm_bridge_macros::ComponentType;
    pub use wasm_bridge_macros::Lift;
    pub use wasm_bridge_macros::Lower;

    /// Loads component from bytes "asynchronously".
    ///
    /// This is just `Component::new()` on sys,
    /// but on js, this will compile WASM cores asynchronously,
    /// which is better.
    pub async fn new_component_async(
        engine: &wasmtime::Engine,
        bytes: impl AsRef<[u8]>,
    ) -> wasmtime::Result<Component> {
        Component::new(engine, bytes)
    }
}

#[cfg(feature = "async")]
pub use async_trait::async_trait;