@@ -48,7 +48,7 @@ impl<_T: 'static> TheWorldPre<_T> {
4848 mut store : impl wasmtime:: AsContextMut < Data = _T > ,
4949 ) -> wasmtime:: Result < TheWorld >
5050 where
51- _T : Send + ' static ,
51+ _T : Send ,
5252 {
5353 let mut store = store. as_context_mut ( ) ;
5454 let instance = self . instance_pre . instantiate_async ( & mut store) . await ?;
@@ -136,7 +136,7 @@ const _: () = {
136136 linker : & wasmtime:: component:: Linker < _T > ,
137137 ) -> wasmtime:: Result < TheWorld >
138138 where
139- _T : Send + ' static ,
139+ _T : Send ,
140140 {
141141 let pre = linker. instantiate_pre ( component) ?;
142142 TheWorldPre :: new ( pre) ?. instantiate_async ( store) . await
@@ -150,16 +150,16 @@ const _: () = {
150150 let indices = TheWorldIndices :: new ( & instance. instance_pre ( & store) ) ?;
151151 indices. load ( & mut store, instance)
152152 }
153- pub fn add_to_linker < T , U > (
153+ pub fn add_to_linker < T , D > (
154154 linker : & mut wasmtime:: component:: Linker < T > ,
155- get : impl Fn ( & mut T ) -> & mut U + Send + Sync + Copy + ' static ,
155+ host_getter : fn ( & mut T ) -> D :: Data < ' _ > ,
156156 ) -> wasmtime:: Result < ( ) >
157157 where
158- T : ' static ,
159- T : Send + foo:: foo:: chars:: Host < Data = T > ,
160- U : Send + foo :: foo :: chars :: Host < Data = T > ,
158+ D : foo :: foo :: chars :: HostConcurrent + Send ,
159+ for < ' a > D :: Data < ' a > : foo:: foo:: chars:: Host + Send ,
160+ T : ' static + Send ,
161161 {
162- foo:: foo:: chars:: add_to_linker ( linker, get ) ?;
162+ foo:: foo:: chars:: add_to_linker :: < T , D > ( linker, host_getter ) ?;
163163 Ok ( ( ) )
164164 }
165165 pub fn foo_foo_chars ( & self ) -> & exports:: foo:: foo:: chars:: Guest {
@@ -173,149 +173,61 @@ pub mod foo {
173173 pub mod chars {
174174 #[ allow( unused_imports) ]
175175 use wasmtime:: component:: __internal:: { anyhow, Box } ;
176- pub trait Host {
177- type Data ;
176+ # [ wasmtime :: component :: __internal :: trait_variant_make ( :: core :: marker :: Send ) ]
177+ pub trait HostConcurrent : wasmtime :: component :: HasData + Send {
178178 /// A function that accepts a character
179- fn take_char (
180- store : wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
179+ fn take_char < T : ' static > (
180+ accessor : & mut wasmtime:: component :: Accessor < T , Self > ,
181181 x : char ,
182- ) -> impl :: core:: future:: Future <
183- Output = impl FnOnce (
184- wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
185- ) -> ( ) + Send + Sync + ' static ,
186- > + Send + Sync + ' static
182+ ) -> impl :: core:: future:: Future < Output = ( ) > + Send
187183 where
188184 Self : Sized ;
189185 /// A function that returns a character
190- fn return_char (
191- store : wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
192- ) -> impl :: core:: future:: Future <
193- Output = impl FnOnce (
194- wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
195- ) -> char + Send + Sync + ' static ,
196- > + Send + Sync + ' static
186+ fn return_char < T : ' static > (
187+ accessor : & mut wasmtime:: component:: Accessor < T , Self > ,
188+ ) -> impl :: core:: future:: Future < Output = char > + Send
197189 where
198190 Self : Sized ;
199191 }
200- pub fn add_to_linker_get_host < T , G > (
192+ #[ wasmtime:: component:: __internal:: trait_variant_make( :: core:: marker:: Send ) ]
193+ pub trait Host : Send { }
194+ impl < _T : Host + ?Sized + Send > Host for & mut _T { }
195+ pub fn add_to_linker < T , D > (
201196 linker : & mut wasmtime:: component:: Linker < T > ,
202- host_getter : G ,
197+ host_getter : fn ( & mut T ) -> D :: Data < ' _ > ,
203198 ) -> wasmtime:: Result < ( ) >
204199 where
205- T : ' static ,
206- G : for < ' a > wasmtime:: component:: GetHost <
207- & ' a mut T ,
208- Host : Host < Data = T > + Send ,
209- > ,
210- T : Send + ' static ,
200+ D : HostConcurrent ,
201+ for < ' a > D :: Data < ' a > : Host ,
202+ T : ' static + Send ,
211203 {
212204 let mut inst = linker. instance ( "foo:foo/chars" ) ?;
213205 inst. func_wrap_concurrent (
214206 "take-char" ,
215207 move |
216- mut caller : wasmtime:: StoreContextMut < ' _ , T > ,
208+ caller : & mut wasmtime:: component :: Accessor < T > ,
217209 ( arg0, ) : ( char , ) |
218210 {
219- let host = caller;
220- let r = <G :: Host as Host >:: take_char ( host, arg0) ;
221- Box :: pin ( async move {
222- let fun = r. await ;
223- Box :: new ( move |mut caller : wasmtime:: StoreContextMut < ' _ , T > | {
224- let r = fun ( caller) ;
225- Ok ( r)
226- } )
227- as Box <
228- dyn FnOnce (
229- wasmtime:: StoreContextMut < ' _ , T > ,
230- ) -> wasmtime:: Result < ( ) > + Send + Sync ,
231- >
211+ wasmtime:: component:: __internal:: Box :: pin ( async move {
212+ let accessor = & mut unsafe { caller. with_data ( host_getter) } ;
213+ let r = <D as HostConcurrent >:: take_char ( accessor, arg0)
214+ . await ;
215+ Ok ( r)
232216 } )
233- as :: core:: pin:: Pin <
234- Box <
235- dyn :: core:: future:: Future <
236- Output = Box <
237- dyn FnOnce (
238- wasmtime:: StoreContextMut < ' _ , T > ,
239- ) -> wasmtime:: Result < ( ) > + Send + Sync ,
240- > ,
241- > + Send + Sync + ' static ,
242- > ,
243- >
244217 } ,
245218 ) ?;
246219 inst. func_wrap_concurrent (
247220 "return-char" ,
248- move |mut caller : wasmtime:: StoreContextMut < ' _ , T > , ( ) : ( ) | {
249- let host = caller;
250- let r = <G :: Host as Host >:: return_char ( host) ;
251- Box :: pin ( async move {
252- let fun = r. await ;
253- Box :: new ( move |mut caller : wasmtime:: StoreContextMut < ' _ , T > | {
254- let r = fun ( caller) ;
255- Ok ( ( r, ) )
256- } )
257- as Box <
258- dyn FnOnce (
259- wasmtime:: StoreContextMut < ' _ , T > ,
260- ) -> wasmtime:: Result < ( char , ) > + Send + Sync ,
261- >
221+ move |caller : & mut wasmtime:: component:: Accessor < T > , ( ) : ( ) | {
222+ wasmtime:: component:: __internal:: Box :: pin ( async move {
223+ let accessor = & mut unsafe { caller. with_data ( host_getter) } ;
224+ let r = <D as HostConcurrent >:: return_char ( accessor) . await ;
225+ Ok ( ( r, ) )
262226 } )
263- as :: core:: pin:: Pin <
264- Box <
265- dyn :: core:: future:: Future <
266- Output = Box <
267- dyn FnOnce (
268- wasmtime:: StoreContextMut < ' _ , T > ,
269- ) -> wasmtime:: Result < ( char , ) > + Send + Sync ,
270- > ,
271- > + Send + Sync + ' static ,
272- > ,
273- >
274227 } ,
275228 ) ?;
276229 Ok ( ( ) )
277230 }
278- pub fn add_to_linker < T , U > (
279- linker : & mut wasmtime:: component:: Linker < T > ,
280- get : impl Fn ( & mut T ) -> & mut U + Send + Sync + Copy + ' static ,
281- ) -> wasmtime:: Result < ( ) >
282- where
283- T : ' static ,
284- U : Host < Data = T > + Send ,
285- T : Send + ' static ,
286- {
287- add_to_linker_get_host ( linker, get)
288- }
289- impl < _T : Host > Host for & mut _T {
290- type Data = _T:: Data ;
291- /// A function that accepts a character
292- fn take_char (
293- store : wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
294- x : char ,
295- ) -> impl :: core:: future:: Future <
296- Output = impl FnOnce (
297- wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
298- ) -> ( ) + Send + Sync + ' static ,
299- > + Send + Sync + ' static
300- where
301- Self : Sized ,
302- {
303- <_T as Host >:: take_char ( store, x)
304- }
305- /// A function that returns a character
306- fn return_char (
307- store : wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
308- ) -> impl :: core:: future:: Future <
309- Output = impl FnOnce (
310- wasmtime:: StoreContextMut < ' _ , Self :: Data > ,
311- ) -> char + Send + Sync + ' static ,
312- > + Send + Sync + ' static
313- where
314- Self : Sized ,
315- {
316- <_T as Host >:: return_char ( store)
317- }
318- }
319231 }
320232 }
321233}
@@ -396,11 +308,13 @@ pub mod exports {
396308 }
397309 impl Guest {
398310 /// A function that accepts a character
399- pub async fn call_take_char < S : wasmtime:: AsContextMut > (
311+ pub fn call_take_char < S : wasmtime:: AsContextMut > (
400312 & self ,
401313 mut store : S ,
402314 arg0 : char ,
403- ) -> wasmtime:: Result < wasmtime:: component:: Promise < ( ) > >
315+ ) -> impl wasmtime:: component:: __internal:: Future <
316+ Output = wasmtime:: Result < ( ) > ,
317+ > + Send + ' static + use < S >
404318 where
405319 <S as wasmtime:: AsContext >:: Data : Send + ' static ,
406320 {
@@ -410,16 +324,15 @@ pub mod exports {
410324 ( ) ,
411325 > :: new_unchecked ( self . take_char )
412326 } ;
413- let promise = callee
414- . call_concurrent ( store. as_context_mut ( ) , ( arg0, ) )
415- . await ?;
416- Ok ( promise)
327+ callee. call_concurrent ( store. as_context_mut ( ) , ( arg0, ) )
417328 }
418329 /// A function that returns a character
419- pub async fn call_return_char < S : wasmtime:: AsContextMut > (
330+ pub fn call_return_char < S : wasmtime:: AsContextMut > (
420331 & self ,
421332 mut store : S ,
422- ) -> wasmtime:: Result < wasmtime:: component:: Promise < char > >
333+ ) -> impl wasmtime:: component:: __internal:: Future <
334+ Output = wasmtime:: Result < char > ,
335+ > + Send + ' static + use < S >
423336 where
424337 <S as wasmtime:: AsContext >:: Data : Send + ' static ,
425338 {
@@ -429,10 +342,10 @@ pub mod exports {
429342 ( char , ) ,
430343 > :: new_unchecked ( self . return_char )
431344 } ;
432- let promise = callee
433- . call_concurrent ( store. as_context_mut ( ) , ( ) )
434- . await ? ;
435- Ok ( promise . map ( | ( v , ) | v ) )
345+ wasmtime :: component :: __internal :: FutureExt :: map (
346+ callee . call_concurrent ( store. as_context_mut ( ) , ( ) ) ,
347+ |v| v . map ( | ( v , ) | v ) ,
348+ )
436349 }
437350 }
438351 }
0 commit comments