1 /// Auto-generated bindings for a pre-instantiated version of a 2 /// component which implements the world `path1`. 3 /// 4 /// This structure is created through [`Path1Pre::new`] which 5 /// takes a [`InstancePre`](wasmtime::component::InstancePre) that 6 /// has been created through a [`Linker`](wasmtime::component::Linker). 7 /// 8 /// For more information see [`Path1`] as well. 9 pub struct Path1Pre<T> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: Path1Indices, 12 } 13 impl<T> Clone for Path1Pre<T> { 14 fn clone(&self) -> Self { 15 Self { 16 instance_pre: self.instance_pre.clone(), 17 indices: self.indices.clone(), 18 } 19 } 20 } 21 impl<_T> Path1Pre<_T> { 22 /// Creates a new copy of `Path1Pre` bindings which can then 23 /// be used to instantiate into a particular store. 24 /// 25 /// This method may fail if the component behind `instance_pre` 26 /// does not have the required exports. 27 pub fn new( 28 instance_pre: wasmtime::component::InstancePre<_T>, 29 ) -> wasmtime::Result<Self> { 30 let indices = Path1Indices::new(&instance_pre)?; 31 Ok(Self { instance_pre, indices }) 32 } 33 pub fn engine(&self) -> &wasmtime::Engine { 34 self.instance_pre.engine() 35 } 36 pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> { 37 &self.instance_pre 38 } 39 /// Instantiates a new instance of [`Path1`] within the 40 /// `store` provided. 41 /// 42 /// This function will use `self` as the pre-instantiated 43 /// instance to perform instantiation. Afterwards the preloaded 44 /// indices in `self` are used to lookup all exports on the 45 /// resulting instance. 46 pub async fn instantiate_async( 47 &self, 48 mut store: impl wasmtime::AsContextMut<Data = _T>, 49 ) -> wasmtime::Result<Path1> 50 where 51 _T: Send, 52 { 53 let mut store = store.as_context_mut(); 54 let instance = self.instance_pre.instantiate_async(&mut store).await?; 55 self.indices.load(&mut store, &instance) 56 } 57 } 58 /// Auto-generated bindings for index of the exports of 59 /// `path1`. 60 /// 61 /// This is an implementation detail of [`Path1Pre`] and can 62 /// be constructed if needed as well. 63 /// 64 /// For more information see [`Path1`] as well. 65 #[derive(Clone)] 66 pub struct Path1Indices {} 67 /// Auto-generated bindings for an instance a component which 68 /// implements the world `path1`. 69 /// 70 /// This structure can be created through a number of means 71 /// depending on your requirements and what you have on hand: 72 /// 73 /// * The most convenient way is to use 74 /// [`Path1::instantiate_async`] which only needs a 75 /// [`Store`], [`Component`], and [`Linker`]. 76 /// 77 /// * Alternatively you can create a [`Path1Pre`] ahead of 78 /// time with a [`Component`] to front-load string lookups 79 /// of exports once instead of per-instantiation. This 80 /// method then uses [`Path1Pre::instantiate_async`] to 81 /// create a [`Path1`]. 82 /// 83 /// * If you've instantiated the instance yourself already 84 /// then you can use [`Path1::new`]. 85 /// 86 /// These methods are all equivalent to one another and move 87 /// around the tradeoff of what work is performed when. 88 /// 89 /// [`Store`]: wasmtime::Store 90 /// [`Component`]: wasmtime::component::Component 91 /// [`Linker`]: wasmtime::component::Linker 92 pub struct Path1 {} 93 const _: () = { 94 #[allow(unused_imports)] 95 use wasmtime::component::__internal::anyhow; 96 impl Path1Indices { 97 /// Creates a new copy of `Path1Indices` bindings which can then 98 /// be used to instantiate into a particular store. 99 /// 100 /// This method may fail if the component does not have the 101 /// required exports. 102 pub fn new<_T>( 103 _instance_pre: &wasmtime::component::InstancePre<_T>, 104 ) -> wasmtime::Result<Self> { 105 let _component = _instance_pre.component(); 106 let _instance_type = _instance_pre.instance_type(); 107 Ok(Path1Indices {}) 108 } 109 /// Uses the indices stored in `self` to load an instance 110 /// of [`Path1`] from the instance provided. 111 /// 112 /// Note that at this time this method will additionally 113 /// perform type-checks of all exports. 114 pub fn load( 115 &self, 116 mut store: impl wasmtime::AsContextMut, 117 instance: &wasmtime::component::Instance, 118 ) -> wasmtime::Result<Path1> { 119 let _ = &mut store; 120 let _instance = instance; 121 Ok(Path1 {}) 122 } 123 } 124 impl Path1 { 125 /// Convenience wrapper around [`Path1Pre::new`] and 126 /// [`Path1Pre::instantiate_async`]. 127 pub async fn instantiate_async<_T>( 128 store: impl wasmtime::AsContextMut<Data = _T>, 129 component: &wasmtime::component::Component, 130 linker: &wasmtime::component::Linker<_T>, 131 ) -> wasmtime::Result<Path1> 132 where 133 _T: Send, 134 { 135 let pre = linker.instantiate_pre(component)?; 136 Path1Pre::new(pre)?.instantiate_async(store).await 137 } 138 /// Convenience wrapper around [`Path1Indices::new`] and 139 /// [`Path1Indices::load`]. 140 pub fn new( 141 mut store: impl wasmtime::AsContextMut, 142 instance: &wasmtime::component::Instance, 143 ) -> wasmtime::Result<Path1> { 144 let indices = Path1Indices::new(&instance.instance_pre(&store))?; 145 indices.load(&mut store, instance) 146 } 147 pub fn add_to_linker<T, U>( 148 linker: &mut wasmtime::component::Linker<T>, 149 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 150 ) -> wasmtime::Result<()> 151 where 152 T: Send, 153 U: paths::path1::test::Host + Send, 154 { 155 paths::path1::test::add_to_linker(linker, get)?; 156 Ok(()) 157 } 158 } 159 }; 160 pub mod paths { 161 pub mod path1 { 162 #[allow(clippy::all)] 163 pub mod test { 164 #[allow(unused_imports)] 165 use wasmtime::component::__internal::{anyhow, Box}; 166 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 167 pub trait Host: Send {} 168 pub trait GetHost< 169 T, 170 D, 171 >: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static { 172 type Host: Host + Send; 173 } 174 impl<F, T, D, O> GetHost<T, D> for F 175 where 176 F: Fn(T) -> O + Send + Sync + Copy + 'static, 177 O: Host + Send, 178 { 179 type Host = O; 180 } 181 pub fn add_to_linker_get_host< 182 T, 183 G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>, 184 >( 185 linker: &mut wasmtime::component::Linker<T>, 186 host_getter: G, 187 ) -> wasmtime::Result<()> 188 where 189 T: Send, 190 { 191 let mut inst = linker.instance("paths:path1/test")?; 192 Ok(()) 193 } 194 pub fn add_to_linker<T, U>( 195 linker: &mut wasmtime::component::Linker<T>, 196 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 197 ) -> wasmtime::Result<()> 198 where 199 U: Host + Send, 200 T: Send, 201 { 202 add_to_linker_get_host(linker, get) 203 } 204 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 205 } 206 } 207 } 208