@@ -23,12 +23,12 @@ use wasmtime::component::types::{Case, Field};
2323use wasmtime:: component:: { ResourceType , Type , Val } ;
2424use wasmtime:: { AsContextMut , StoreContextMut } ;
2525use wasmtime_wasi:: p2:: pipe:: AsyncReadStream ;
26- use wasmtime_wasi:: p2:: { DynInputStream , StreamError , WasiView } ;
26+ use wasmtime_wasi:: p2:: { DynInputStream , StreamError } ;
2727use wrpc_transport:: ListDecoderU8 ;
2828
2929use crate :: { RemoteResource , WrpcView } ;
3030
31- pub struct ValEncoder < ' a , T , W > {
31+ pub struct ValEncoder < ' a , T : ' static , W > {
3232 pub store : StoreContextMut < ' a , T > ,
3333 pub ty : & ' a Type ,
3434 pub resources : & ' a [ ResourceType ] ,
@@ -120,7 +120,7 @@ where
120120
121121impl < T , W > Encoder < & Val > for ValEncoder < ' _ , T , W >
122122where
123- T : WasiView + WrpcView ,
123+ T : WrpcView ,
124124 W : AsyncWrite + wrpc_transport:: Index < W > + Sync + Send + ' static ,
125125{
126126 type Error = wasmtime:: Error ;
@@ -449,7 +449,8 @@ where
449449 let mut stream = self
450450 . store
451451 . data_mut ( )
452- . table ( )
452+ . wrpc ( )
453+ . table
453454 . delete ( stream)
454455 . context ( "failed to delete input stream" ) ?;
455456 self . deferred = Some ( Box :: new ( |w| {
@@ -478,7 +479,8 @@ where
478479 } else {
479480 self . store
480481 . data_mut ( )
481- . table ( )
482+ . wrpc ( )
483+ . table
482484 . get_mut ( & stream)
483485 . context ( "failed to get input stream" ) ?;
484486 // NOTE: In order to handle this we'd need to know how many bytes the
@@ -491,7 +493,7 @@ where
491493 let resource = resource
492494 . try_into_resource ( & mut self . store )
493495 . context ( "resource type mismatch" ) ?;
494- let table = self . store . data_mut ( ) . table ( ) ;
496+ let table = self . store . data_mut ( ) . wrpc ( ) . table ;
495497 if resource. owned ( ) {
496498 let RemoteResource ( buf) = table
497499 . delete ( resource)
@@ -516,6 +518,8 @@ where
516518 if self
517519 . store
518520 . data_mut ( )
521+ . wrpc ( )
522+ . ctx
519523 . shared_resources ( )
520524 . 0
521525 . insert ( id, * resource)
@@ -528,6 +532,10 @@ where
528532 bail ! ( "encoding host resources not supported yet" )
529533 }
530534 }
535+
536+ ( _, Type :: Future ( ..) | Type :: Stream ( ..) | Type :: ErrorContext ) => {
537+ bail ! ( "async not supported" )
538+ }
531539 _ => bail ! ( "value type mismatch" ) ,
532540 }
533541 }
@@ -551,7 +559,7 @@ pub async fn read_value<T, R>(
551559 path : & [ usize ] ,
552560) -> std:: io:: Result < ( ) >
553561where
554- T : WasiView + WrpcView ,
562+ T : WrpcView + ' static ,
555563 R : AsyncRead + wrpc_transport:: Index < R > + Send + Unpin + ' static ,
556564{
557565 match ty {
@@ -796,7 +804,8 @@ where
796804 // which will could potentially break/hang with some transports
797805 let res = store
798806 . data_mut ( )
799- . table ( )
807+ . wrpc ( )
808+ . table
800809 . push ( Box :: new ( AsyncReadStream :: new (
801810 FramedRead :: new ( r, ListDecoderU8 :: default ( ) )
802811 . into_async_read ( )
@@ -837,6 +846,8 @@ where
837846 trace ! ( ?id, "lookup shared resource" ) ;
838847 let resource = store
839848 . data_mut ( )
849+ . wrpc ( )
850+ . ctx
840851 . shared_resources ( )
841852 . 0
842853 . get ( & id)
@@ -850,7 +861,7 @@ where
850861 . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , err) ) ?;
851862 let mut buf = Vec :: with_capacity ( n) ;
852863 r. read_to_end ( & mut buf) . await ?;
853- let table = store. data_mut ( ) . table ( ) ;
864+ let table = store. data_mut ( ) . wrpc ( ) . table ;
854865 let resource = table
855866 . push ( RemoteResource ( buf. into ( ) ) )
856867 . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: OutOfMemory , err) ) ?;
@@ -861,5 +872,9 @@ where
861872 Ok ( ( ) )
862873 }
863874 }
875+ Type :: Future ( ..) | Type :: Stream ( ..) | Type :: ErrorContext => Err ( std:: io:: Error :: new (
876+ std:: io:: ErrorKind :: Unsupported ,
877+ "async not supported" ,
878+ ) ) ,
864879 }
865880}
0 commit comments