Description
Right now, the serialization interface requires that the type to be serialized be generic with respect to any sort of serializer:
trait Serializable { fn serialize<S: Serializer>(&self, s: &s); }
Unfortunately, some types require context to be serialized, such as ty::t
or span
. When doing the original design I had intended that this state would be carried in the serializer, but of course if you must write the serialization function generically that didn't work, so we ended up with ast_encode.rs
which does some manual serialization for any type that touches ty::t
. At first this wasn't a lot of stuff but of course it's growing and it's annoying.
One way to solve this is to modify the Serializable
trait as follows:
trait Serializable<S: Serializer> { fn serialize(&self, s: &s); }
This allows a type to implement Serializable
only for specific serializers:
impl ty::t: Serializable<RustcSerializer> { ... }
To really make this work, though, it is also necessary for the auto_serialize
code to permit generation of an impl that is specialized to a particular serializer, since any struct which contains ty::t
values will also only work with RustcSerializer.
Another option would be to extend the Serializable
trait with some kind of state and carry that around, but I think that winds up just being more type parameters without really adding any sort of flexibility.
@erickt has done preliminary work but it's hitting an ICE somewhere in the static methods implementation. I haven't tracked down the cause.