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