wasm-tools icon indicating copy to clipboard operation
wasm-tools copied to clipboard

Add `From` implementations for structural types to `StructuralType`, `SubType` and `Type`

Open imikushin opened this issue 2 years ago • 0 comments

Looking at all these conversions between Type, SubType, StructuralType, and each structural type variant, it seems like we could have some more From implementations to make this less noisy and more automatic.

To really benefit from this, and because From is not transitive by default, I think we would want all of these impls:

impl From<FuncType> for StructuralType { ... }
impl From<ArrayType> for StructuralType { ... }
impl From<StructType> for StructuralType { ... }

impl From<StructuralType> for SubType { ... }
impl From<FuncType> for SubType { ... }
impl From<ArrayType> for SubType { ... }
impl From<StructType> for SubType { ... }

impl From<SubType> for Type { ... }
impl From<StructuralType> for Type { ... }
impl From<FuncType> for Type { ... }
impl From<ArrayType> for Type { ... }
impl From<StructType> for Type { ... }

Originally posted by @fitzgen in https://github.com/bytecodealliance/wasm-tools/pull/1059#discussion_r1230108885

imikushin avatar Jun 14 '23 23:06 imikushin