-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Serializing map types #4115
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
Comments
This seems like a good idea to me. I presume what you mean is to add methods to the Serializer interface for maps, even though |
Thinking about this a bit more: one tricky issue that comes to mind is how to manage deserialization. I guess it'd be up to the deserializer to select an appropriate map implementation? Maybe we can supply a hint as part of the serialization as to what kind of map this originally was? Maybe we want a base serializer/deserializer interface that is more-or-less what we have now, and then some extended variants? |
An example of how this would be useful is how do we encode a map to and from json? Say we wanted to write this:
We could make a serializer like this:
However, serializers support maps with non-string keys, like MessagePack (http://msgpack.org/). So to support that, we would have to write our impl to emit a vector of tuples, like this:
It would take some effort to write serializers to infer that a vector of 2-tuples is actually a map, and generate a proper native map. Adding |
@nikomatsakis: Good point. Maybe we just provide deserializers for concrete types? |
@nikomatsakis: Yes, these |
Ironically, this doesn't necessarily help out serializing maps to json. If we do support non-string-key maps, then if you want to serialize
I'd love to have trait specialization for this case, but I'm sure that adds a whole host of other problems. |
(Responding to myself again) I do remember some talk of making a |
Added "far future" milestone |
(Deserialization, I realize now, is a non-issue: when deserializing, you always have the type you are deserializing into.) |
Revisiting for bug triage. I agree with my earlier self. |
Currently there's a serialization/deserialization for HashMap/HashSet/TreeMap/TrieMap. Also, there's a function in the I think that this satisfies what the bug was originally for, but feel free to reopen if it's intended for something else! |
epoll: avoid some clones
std::serialization
does not directly support serializing a map structure likeLinearMap
. Should we support it as a top-level construct? Records and structs are similar, but this map would allow for serializing non-string keys.The text was updated successfully, but these errors were encountered: