@@ -937,3 +937,93 @@ pub unsafe extern "C" fn wasmtime_eqref_as_array(
937937 crate :: initialize ( out, None :: < OwnedRooted < ArrayRef > > . into ( ) ) ;
938938 false
939939}
940+
941+ #[ unsafe( no_mangle) ]
942+ pub unsafe extern "C" fn wasmtime_anyref_is_eqref (
943+ cx : WasmtimeStoreContextMut < ' _ > ,
944+ anyref : Option < & wasmtime_anyref_t > ,
945+ ) -> bool {
946+ match anyref. and_then ( |a| a. as_wasmtime ( ) ) {
947+ Some ( anyref) => anyref. is_eqref ( & cx) . expect ( "OwnedRooted always in scope" ) ,
948+ None => false ,
949+ }
950+ }
951+
952+ #[ unsafe( no_mangle) ]
953+ pub unsafe extern "C" fn wasmtime_anyref_as_eqref (
954+ mut cx : WasmtimeStoreContextMut < ' _ > ,
955+ anyref : Option < & wasmtime_anyref_t > ,
956+ out : & mut MaybeUninit < wasmtime_eqref_t > ,
957+ ) -> bool {
958+ if let Some ( anyref) = anyref. and_then ( |a| a. as_wasmtime ( ) ) {
959+ let mut scope = RootScope :: new ( & mut cx) ;
960+ let rooted = anyref. to_rooted ( & mut scope) ;
961+ if let Ok ( Some ( eqref) ) = rooted. as_eqref ( & mut scope) {
962+ let owned = eqref. to_owned_rooted ( & mut scope) . expect ( "in scope" ) ;
963+ crate :: initialize ( out, Some ( owned) . into ( ) ) ;
964+ return true ;
965+ }
966+ }
967+ crate :: initialize ( out, None :: < OwnedRooted < EqRef > > . into ( ) ) ;
968+ false
969+ }
970+
971+ #[ unsafe( no_mangle) ]
972+ pub unsafe extern "C" fn wasmtime_anyref_is_struct (
973+ cx : WasmtimeStoreContextMut < ' _ > ,
974+ anyref : Option < & wasmtime_anyref_t > ,
975+ ) -> bool {
976+ match anyref. and_then ( |a| a. as_wasmtime ( ) ) {
977+ Some ( anyref) => anyref. is_struct ( & cx) . expect ( "OwnedRooted always in scope" ) ,
978+ None => false ,
979+ }
980+ }
981+
982+ #[ unsafe( no_mangle) ]
983+ pub unsafe extern "C" fn wasmtime_anyref_as_struct (
984+ mut cx : WasmtimeStoreContextMut < ' _ > ,
985+ anyref : Option < & wasmtime_anyref_t > ,
986+ out : & mut MaybeUninit < wasmtime_structref_t > ,
987+ ) -> bool {
988+ if let Some ( anyref) = anyref. and_then ( |a| a. as_wasmtime ( ) ) {
989+ let mut scope = RootScope :: new ( & mut cx) ;
990+ let rooted = anyref. to_rooted ( & mut scope) ;
991+ if let Ok ( Some ( structref) ) = rooted. as_struct ( & scope) {
992+ let owned = structref. to_owned_rooted ( & mut scope) . expect ( "in scope" ) ;
993+ crate :: initialize ( out, Some ( owned) . into ( ) ) ;
994+ return true ;
995+ }
996+ }
997+ crate :: initialize ( out, None :: < OwnedRooted < StructRef > > . into ( ) ) ;
998+ false
999+ }
1000+
1001+ #[ unsafe( no_mangle) ]
1002+ pub unsafe extern "C" fn wasmtime_anyref_is_array (
1003+ cx : WasmtimeStoreContextMut < ' _ > ,
1004+ anyref : Option < & wasmtime_anyref_t > ,
1005+ ) -> bool {
1006+ match anyref. and_then ( |a| a. as_wasmtime ( ) ) {
1007+ Some ( anyref) => anyref. is_array ( & cx) . expect ( "OwnedRooted always in scope" ) ,
1008+ None => false ,
1009+ }
1010+ }
1011+
1012+ #[ unsafe( no_mangle) ]
1013+ pub unsafe extern "C" fn wasmtime_anyref_as_array (
1014+ mut cx : WasmtimeStoreContextMut < ' _ > ,
1015+ anyref : Option < & wasmtime_anyref_t > ,
1016+ out : & mut MaybeUninit < wasmtime_arrayref_t > ,
1017+ ) -> bool {
1018+ if let Some ( anyref) = anyref. and_then ( |a| a. as_wasmtime ( ) ) {
1019+ let mut scope = RootScope :: new ( & mut cx) ;
1020+ let rooted = anyref. to_rooted ( & mut scope) ;
1021+ if let Ok ( Some ( arrayref) ) = rooted. as_array ( & scope) {
1022+ let owned = arrayref. to_owned_rooted ( & mut scope) . expect ( "in scope" ) ;
1023+ crate :: initialize ( out, Some ( owned) . into ( ) ) ;
1024+ return true ;
1025+ }
1026+ }
1027+ crate :: initialize ( out, None :: < OwnedRooted < ArrayRef > > . into ( ) ) ;
1028+ false
1029+ }
0 commit comments