-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to make str -> ron::Value lossless #553
base: master
Are you sure you want to change the base?
Conversation
What if type (and field) names are stored using a Cow<‘static, str>? On deserialize, we just fill in a String. On serialise, we fail if the Cow is borrowed. Value then gets a convenience method to leak all owned strings (in the future we could also add a method that uses an interner so that no duplicate leaks occur). |
That seems like a nice work around |
No quite - unit structs and unit variants are serialized in RON as |
Another issue is that RON treats structs and enum variants mostly the same, except that structs can be serialized and deserialized without the name. So if we serialize an enum variant into The other option would be to have explicitly distinct variants for enums. Serializing to Value would not be an issue and serializing the Value to a string would also work. When deserializing from a string we'd have to accept that there would now be implementation-defined ambiguity as to whether |
If you're interested in other workarounds for the |
This is my last version of pub enum Value {
Unit,
Bool(bool),
Char(char),
Number(Number),
String(String),
Bytes(Vec<u8>),
Option(Option<Box<Value>>),
List(Vec<Value>),
Map(Map<Value>),
Tuple(Vec<Value>),
UnitStructOrEnumVariant(Cow<'static, str>),
UnitEnumVariant(Cow<'static, str>),
UnitStruct(Cow<'static, str>),
StructOrEnumVariant(Option<Cow<'static, str>>, Map<Cow<'static, str>>),
Struct(Option<Cow<'static, str>>, Map<Cow<'static, str>>),
EnumVariant(Cow<'static, str>, Map<Cow<'static, str>>),
EnumTuple(Cow<'static, str>, Vec<Value>),
} It define variant for case when we don't know the exact type of the value. This way, we can provide option for serialization, like don't write the name of struct, while being conservative when we don't know if we can remove it. |
Let's go with this Value for now, I think we'll learn more during the implementation of serialising to it and deserialising from it. |
This PR have the same goal of #328 (i just saw it while opening this one)
This PR currently do not even compile. I'm only opening it for visibility/feedback. I think my
map
module have some potential though.I came across a potential blocker (serde-rs/serde#2218). The name of a struct need to have a static lifetime somehow. I think i will try to workaround it by leaking memory for now.
I still need to figuring out the de serialization part