We're currently using intertrait, which depends on linkme. While it works on Linux, macOS and Windows, it might not work elsewhere as it's platform-dependent.
It's a bit crude and is certainly less ergonomic (compared to intertrait) but it seems to work.
The idea is to make DocumentElement trait implement Cast<T> where T is all Type and TypeMut traits and then auto-generate implementations of this Cast<T> trait for every struct and enum.
One downside of this approach is that autogenerated.rs is much bigger now (approaching 7Mb). That being said, it might eventually be generated during build-time and we won't have to distribute it as is. I suppose the amount of actual code generated by trait casting crates is effectively of a similar size.
We're currently using intertrait, which depends on linkme. While it works on Linux, macOS and Windows, it might not work elsewhere as it's platform-dependent.
In fact, there's no support for WebAssembly: https://github.com/dtolnay/linkme/issues/6 and that's one of the goals for BPXE.
Solution: roll our own
Cast
traitIt's a bit crude and is certainly less ergonomic (compared to
intertrait
) but it seems to work.The idea is to make
DocumentElement
trait implementCast<T>
whereT
is allType
andTypeMut
traits and then auto-generate implementations of thisCast<T>
trait for every struct and enum.One downside of this approach is that
autogenerated.rs
is much bigger now (approaching 7Mb). That being said, it might eventually be generated during build-time and we won't have to distribute it as is. I suppose the amount of actual code generated by trait casting crates is effectively of a similar size.Closes #8