You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
Option types as HashMap keys is problematic when used with rustc-serialize. The issue is that if you use None as a key and try to serialize it, it will serialize to something like "null": /* value */. Note that this is the string null, and not the keyword null. As a result, when you try to decode it from JSON, you run into this issue: if you have an Option<String>, it'll decode as Some(null) instead of None. If you have a non-String type (e.g. u8), it will fail with an error. This issue is made more complex by the fact that there isn't a clear answer, at least that I can see, within the JSON specification. With the way HashMaps are encoded (as objects per the spec), the only valid key value is a string.
Here is the code where I encountered the issue. Here is an example of a HashMap<Option<String>, HashMap<Option<String>, uint>> being serialized:
I don't see how Option<String> could ever be encoded safely and trivially comprehensible. Or even Something like Option<SomeEnumWithAVariantNamedNone>.
Option types as HashMap keys is problematic when used with rustc-serialize. The issue is that if you use
None
as a key and try to serialize it, it will serialize to something like"null": /* value */
. Note that this is the string null, and not the keyword null. As a result, when you try to decode it from JSON, you run into this issue: if you have anOption<String>
, it'll decode asSome(null)
instead ofNone
. If you have a non-String type (e.g. u8), it will fail with an error. This issue is made more complex by the fact that there isn't a clear answer, at least that I can see, within the JSON specification. With the way HashMaps are encoded (as objects per the spec), the only valid key value is a string.Here is the code where I encountered the issue. Here is an example of a
HashMap<Option<String>, HashMap<Option<String>, uint>>
being serialized:All the
"null"
keys were originallyNone
.The text was updated successfully, but these errors were encountered: