pub struct Imports {} const _: () = { #[allow(unused_imports)] use wasmtime::component::__internal::anyhow; impl Imports { pub fn add_to_linker( linker: &mut wasmtime::component::Linker, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, ) -> wasmtime::Result<()> where U: a::b::interface_with_live_type::Host + a::b::interface_with_dead_type::Host, { a::b::interface_with_live_type::add_to_linker(linker, get)?; a::b::interface_with_dead_type::add_to_linker(linker, get)?; Ok(()) } /// Instantiates the provided `module` using the specified /// parameters, wrapping up the result in a structure that /// translates between wasm and the host. pub fn instantiate( mut store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker, ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> { let instance = linker.instantiate(&mut store, component)?; Ok((Self::new(store, &instance)?, instance)) } /// Instantiates a pre-instantiated module using the specified /// parameters, wrapping up the result in a structure that /// translates between wasm and the host. pub fn instantiate_pre( mut store: impl wasmtime::AsContextMut, instance_pre: &wasmtime::component::InstancePre, ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> { let instance = instance_pre.instantiate(&mut store)?; Ok((Self::new(store, &instance)?, instance)) } /// Low-level creation wrapper for wrapping up the exports /// of the `instance` provided in this structure of wasm /// exports. /// /// This function will extract exports from the `instance` /// defined within `store` and wrap them all up in the /// returned structure which can be used to interact with /// the wasm module. pub fn new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result { let mut store = store.as_context_mut(); let mut exports = instance.exports(&mut store); let mut __exports = exports.root(); Ok(Imports {}) } } }; pub mod a { pub mod b { #[allow(clippy::all)] pub mod interface_with_live_type { #[allow(unused_imports)] use wasmtime::component::__internal::anyhow; #[derive(wasmtime::component::ComponentType)] #[derive(wasmtime::component::Lift)] #[derive(wasmtime::component::Lower)] #[component(record)] #[derive(Clone, Copy)] pub struct LiveType { #[component(name = "a")] pub a: u32, } impl core::fmt::Debug for LiveType { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("LiveType").field("a", &self.a).finish() } } const _: () = { assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32); assert!( 4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32 ); }; pub trait Host { fn f(&mut self) -> LiveType; } pub fn add_to_linker( linker: &mut wasmtime::component::Linker, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, ) -> wasmtime::Result<()> where U: Host, { let mut inst = linker.instance("a:b/interface-with-live-type")?; inst.func_wrap( "f", move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { let host = get(caller.data_mut()); let r = Host::f(host); Ok((r,)) }, )?; Ok(()) } } #[allow(clippy::all)] pub mod interface_with_dead_type { #[allow(unused_imports)] use wasmtime::component::__internal::anyhow; pub trait Host {} pub fn add_to_linker( linker: &mut wasmtime::component::Linker, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, ) -> wasmtime::Result<()> where U: Host, { let mut inst = linker.instance("a:b/interface-with-dead-type")?; Ok(()) } } } }