@@ -180,6 +180,32 @@ impl WasmValue {
180180 }
181181}
182182
183+ /// a wrapper for `funcref` value for use in typed wrappers
184+ #[ derive( Clone , Copy , PartialEq , Debug ) ]
185+ pub struct WasmFuncRef ( FuncAddr ) ;
186+
187+ /// a wrapper for `externref` value for use in typed wrappers
188+ #[ derive( Clone , Copy , PartialEq , Debug ) ]
189+ pub struct WasmExternRef ( ExternAddr ) ;
190+
191+ macro_rules! impl_newtype_from_into {
192+ ( $wrapper: ty, $underlying: ty) => {
193+ impl From <$underlying> for $wrapper {
194+ fn from( value: $underlying) -> Self {
195+ Self ( value)
196+ }
197+ }
198+ impl From <$wrapper> for $underlying {
199+ fn from( value: $wrapper) -> Self {
200+ value. 0
201+ }
202+ }
203+ } ;
204+ }
205+
206+ impl_newtype_from_into ! ( WasmFuncRef , FuncAddr ) ;
207+ impl_newtype_from_into ! ( WasmExternRef , ExternAddr ) ;
208+
183209/// Type of a WebAssembly value.
184210#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
185211#[ cfg_attr( feature = "archive" , derive( rkyv:: Archive , rkyv:: Serialize , rkyv:: Deserialize ) ) ]
@@ -219,7 +245,7 @@ macro_rules! impl_conversion_for_wasmvalue {
219245 impl From <$t> for WasmValue {
220246 #[ inline]
221247 fn from( i: $t) -> Self {
222- Self :: $variant( i)
248+ Self :: $variant( i. into ( ) )
223249 }
224250 }
225251
@@ -230,7 +256,7 @@ macro_rules! impl_conversion_for_wasmvalue {
230256 #[ inline]
231257 fn try_from( value: WasmValue ) -> Result <Self , Self :: Error > {
232258 if let WasmValue :: $variant( i) = value {
233- Ok ( i)
259+ Ok ( i. into ( ) )
234260 } else {
235261 cold( ) ;
236262 Err ( ( ) )
@@ -241,4 +267,4 @@ macro_rules! impl_conversion_for_wasmvalue {
241267 }
242268}
243269
244- impl_conversion_for_wasmvalue ! { i32 => I32 , i64 => I64 , f32 => F32 , f64 => F64 , u128 => V128 }
270+ impl_conversion_for_wasmvalue ! { i32 => I32 , i64 => I64 , f32 => F32 , f64 => F64 , u128 => V128 , WasmFuncRef => RefFunc , WasmExternRef => RefExtern }
0 commit comments