make value roundtrip
previous pr: #553
todo:
- [ ] add more test cases (currently, only Enum::A pass)
- [ ] handle all struct type in
handle_any_struct - [ ] finish implementing
visit_enum - [ ] impl
SerializeforValue - [ ] clean up code
- [ ] I've included my change in
CHANGELOG.md
honestly, after having passed way to much time on this, i think its just not possible.
We just need to attach a name to Tuple and Map.
To create a Value, we need a Visitor. The only method capable of this in Visitor is visit_enum.
But,
- the visitor must be generic. It doesn't know in advance the type of the enum.
- the
VariantAccesstrait have
all this method takefn unit_variant(self) -> Result<(), Self::Error>; fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> fn tuple_variant<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error> fn struct_variant<V>( self, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>self, so we can't all call them to know what is the type of the enum.
So we are cooked. I wonder if a language succeed to do this. Maybe i can be proven wrong.
I think we just need another method on VariantAccess:
fn enum_type(&self) -> Option<EnumType>;
enum EnumType {
Unit,
NewType,
Tuple,
Struct
}
https://github.com/serde-rs/serde/issues/2874
Thank you for exploring it further @wiiznokes! I personally think that many improvements are still blocked on serde, perhaps we can come back to this once ron is given more agency in deserialising data without type information
Another solution could be to not implement Deserialize for Value. I don't think it's very used in its current shape anyway since it doesn't store enum