@@ -111,15 +111,17 @@ impl fmt::Display for CoreExtern {
111111 }
112112}
113113
114- impl From < wasmparser:: TableType > for CoreExtern {
115- fn from ( ty : wasmparser:: TableType ) -> Self {
116- Self :: Table {
117- element_type : ty. element_type . into ( ) ,
114+ impl TryFrom < wasmparser:: TableType > for CoreExtern {
115+ type Error = anyhow:: Error ;
116+
117+ fn try_from ( ty : wasmparser:: TableType ) -> anyhow:: Result < Self > {
118+ Ok ( Self :: Table {
119+ element_type : ty. element_type . try_into ( ) ?,
118120 initial : ty. initial ,
119121 maximum : ty. maximum ,
120122 table64 : ty. table64 ,
121123 shared : ty. shared ,
122- }
124+ } )
123125 }
124126}
125127
@@ -135,13 +137,15 @@ impl From<wasmparser::MemoryType> for CoreExtern {
135137 }
136138}
137139
138- impl From < wasmparser:: GlobalType > for CoreExtern {
139- fn from ( ty : wasmparser:: GlobalType ) -> Self {
140- Self :: Global {
141- val_type : ty. content_type . into ( ) ,
140+ impl TryFrom < wasmparser:: GlobalType > for CoreExtern {
141+ type Error = anyhow:: Error ;
142+
143+ fn try_from ( ty : wasmparser:: GlobalType ) -> anyhow:: Result < Self > {
144+ Ok ( Self :: Global {
145+ val_type : ty. content_type . try_into ( ) ?,
142146 mutable : ty. mutable ,
143147 shared : ty. shared ,
144- }
148+ } )
145149 }
146150}
147151
@@ -177,16 +181,18 @@ impl fmt::Display for CoreType {
177181 }
178182}
179183
180- impl From < wasmparser:: ValType > for CoreType {
181- fn from ( ty : wasmparser:: ValType ) -> Self {
182- match ty {
184+ impl TryFrom < wasmparser:: ValType > for CoreType {
185+ type Error = anyhow:: Error ;
186+
187+ fn try_from ( ty : wasmparser:: ValType ) -> anyhow:: Result < Self > {
188+ Ok ( match ty {
183189 wasmparser:: ValType :: I32 => Self :: I32 ,
184190 wasmparser:: ValType :: I64 => Self :: I64 ,
185191 wasmparser:: ValType :: F32 => Self :: F32 ,
186192 wasmparser:: ValType :: F64 => Self :: F64 ,
187193 wasmparser:: ValType :: V128 => Self :: V128 ,
188- wasmparser:: ValType :: Ref ( ty) => Self :: Ref ( ty. into ( ) ) ,
189- }
194+ wasmparser:: ValType :: Ref ( ty) => Self :: Ref ( ty. try_into ( ) ? ) ,
195+ } )
190196 }
191197}
192198
@@ -253,12 +259,14 @@ impl fmt::Display for CoreRefType {
253259 }
254260}
255261
256- impl From < wasmparser:: RefType > for CoreRefType {
257- fn from ( ty : wasmparser:: RefType ) -> Self {
258- Self {
262+ impl TryFrom < wasmparser:: RefType > for CoreRefType {
263+ type Error = anyhow:: Error ;
264+
265+ fn try_from ( ty : wasmparser:: RefType ) -> anyhow:: Result < Self > {
266+ Ok ( Self {
259267 nullable : ty. is_nullable ( ) ,
260- heap_type : ty. heap_type ( ) . into ( ) ,
261- }
268+ heap_type : ty. heap_type ( ) . try_into ( ) ? ,
269+ } )
262270 }
263271}
264272
@@ -316,9 +324,11 @@ pub enum HeapType {
316324 NoCont ,
317325}
318326
319- impl From < wasmparser:: HeapType > for HeapType {
320- fn from ( ty : wasmparser:: HeapType ) -> Self {
321- match ty {
327+ impl TryFrom < wasmparser:: HeapType > for HeapType {
328+ type Error = anyhow:: Error ;
329+
330+ fn try_from ( ty : wasmparser:: HeapType ) -> anyhow:: Result < Self > {
331+ Ok ( match ty {
322332 wasmparser:: HeapType :: Abstract { shared : false , ty } => match ty {
323333 wasmparser:: AbstractHeapType :: Any => Self :: Any ,
324334 wasmparser:: AbstractHeapType :: Func => Self :: Func ,
@@ -336,15 +346,15 @@ impl From<wasmparser::HeapType> for HeapType {
336346 wasmparser:: AbstractHeapType :: NoCont => Self :: NoCont ,
337347 } ,
338348 wasmparser:: HeapType :: Abstract { shared : true , ty } => {
339- panic ! ( "shared heap types are not supported: {:?}" , ty )
349+ anyhow :: bail !( "shared heap types are not supported: {ty :?}" )
340350 }
341351 wasmparser:: HeapType :: Concrete ( index) => {
342352 Self :: Concrete ( index. as_module_index ( ) . unwrap ( ) )
343353 }
344354 wasmparser:: HeapType :: Exact ( _) => {
345- todo ! ( "wasmparser::HeapType::Exact" ) ;
355+ anyhow :: bail !( "exact heap types are not yet supported" )
346356 }
347- }
357+ } )
348358 }
349359}
350360
0 commit comments