1 pub struct Imports {} 2 const _: () = { 3 #[allow(unused_imports)] 4 use wasmtime::component::__internal::anyhow; 5 impl Imports { 6 pub fn add_to_linker<T, U>( 7 linker: &mut wasmtime::component::Linker<T>, 8 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 9 ) -> wasmtime::Result<()> 10 where 11 U: a::b::interface_with_live_type::Host 12 + a::b::interface_with_dead_type::Host + Send, 13 T: Send, 14 { 15 a::b::interface_with_live_type::add_to_linker(linker, get)?; 16 a::b::interface_with_dead_type::add_to_linker(linker, get)?; 17 Ok(()) 18 } 19 /// Instantiates the provided `module` using the specified 20 /// parameters, wrapping up the result in a structure that 21 /// translates between wasm and the host. 22 pub async fn instantiate_async<T: Send>( 23 mut store: impl wasmtime::AsContextMut<Data = T>, 24 component: &wasmtime::component::Component, 25 linker: &wasmtime::component::Linker<T>, 26 ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> { 27 let instance = linker.instantiate_async(&mut store, component).await?; 28 Ok((Self::new(store, &instance)?, instance)) 29 } 30 /// Instantiates a pre-instantiated module using the specified 31 /// parameters, wrapping up the result in a structure that 32 /// translates between wasm and the host. 33 pub async fn instantiate_pre<T: Send>( 34 mut store: impl wasmtime::AsContextMut<Data = T>, 35 instance_pre: &wasmtime::component::InstancePre<T>, 36 ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> { 37 let instance = instance_pre.instantiate_async(&mut store).await?; 38 Ok((Self::new(store, &instance)?, instance)) 39 } 40 /// Low-level creation wrapper for wrapping up the exports 41 /// of the `instance` provided in this structure of wasm 42 /// exports. 43 /// 44 /// This function will extract exports from the `instance` 45 /// defined within `store` and wrap them all up in the 46 /// returned structure which can be used to interact with 47 /// the wasm module. 48 pub fn new( 49 mut store: impl wasmtime::AsContextMut, 50 instance: &wasmtime::component::Instance, 51 ) -> wasmtime::Result<Self> { 52 let mut store = store.as_context_mut(); 53 let mut exports = instance.exports(&mut store); 54 let mut __exports = exports.root(); 55 Ok(Imports {}) 56 } 57 } 58 }; 59 pub mod a { 60 pub mod b { 61 #[allow(clippy::all)] 62 pub mod interface_with_live_type { 63 #[allow(unused_imports)] 64 use wasmtime::component::__internal::anyhow; 65 #[derive(wasmtime::component::ComponentType)] 66 #[derive(wasmtime::component::Lift)] 67 #[derive(wasmtime::component::Lower)] 68 #[component(record)] 69 #[derive(Clone, Copy)] 70 pub struct LiveType { 71 #[component(name = "a")] 72 pub a: u32, 73 } 74 impl core::fmt::Debug for LiveType { 75 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 76 f.debug_struct("LiveType").field("a", &self.a).finish() 77 } 78 } 79 const _: () = { 80 assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32); 81 assert!( 82 4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32 83 ); 84 }; 85 #[wasmtime::component::__internal::async_trait] 86 pub trait Host { 87 async fn f(&mut self) -> LiveType; 88 } 89 pub fn add_to_linker<T, U>( 90 linker: &mut wasmtime::component::Linker<T>, 91 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 92 ) -> wasmtime::Result<()> 93 where 94 T: Send, 95 U: Host + Send, 96 { 97 let mut inst = linker.instance("a:b/interface-with-live-type")?; 98 inst.func_wrap_async( 99 "f", 100 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move { 101 let host = get(caller.data_mut()); 102 let r = Host::f(host).await; 103 Ok((r,)) 104 }), 105 )?; 106 Ok(()) 107 } 108 } 109 #[allow(clippy::all)] 110 pub mod interface_with_dead_type { 111 #[allow(unused_imports)] 112 use wasmtime::component::__internal::anyhow; 113 #[wasmtime::component::__internal::async_trait] 114 pub trait Host {} 115 pub fn add_to_linker<T, U>( 116 linker: &mut wasmtime::component::Linker<T>, 117 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 118 ) -> wasmtime::Result<()> 119 where 120 T: Send, 121 U: Host + Send, 122 { 123 let mut inst = linker.instance("a:b/interface-with-dead-type")?; 124 Ok(()) 125 } 126 } 127 } 128 } 129