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
When annotating a map type (e.g. HashMap) field with #[serde(flatten)] the generated code ultimately calls Serializer::collect_map which in turn calls FlatMapSerializeMap::serialize_entry.
As this function is not implemented on FlatMapSerializeMap the default SerializeMap::serialize_entry implementation delegates this to calls of FlatMapSerializeMap::serialize_key and FlatMapSerializeMap::serialize_value.
This is a problem for SerializeMap implementations which only implement the serialize_entry function (e.g. because the serialized key depends on the value type, as is the case in https://github.com/PistonDevelopers/hematite_nbt where in NBT the value type tag is written to binary before the key is).
As every SerializeMap implementation that implements serialize_key and serialize_value has a default implementation for serialize_entry there shouldn't be any downsides to implementing this change.
The text was updated successfully, but these errors were encountered:
When annotating a map type (e.g.
HashMap
) field with#[serde(flatten)]
the generated code ultimately callsSerializer::collect_map
which in turn callsFlatMapSerializeMap::serialize_entry
.serde/serde/src/ser/mod.rs
Lines 1314 to 1326 in 95b1a5d
As this function is not implemented on
FlatMapSerializeMap
the defaultSerializeMap::serialize_entry
implementation delegates this to calls ofFlatMapSerializeMap::serialize_key
andFlatMapSerializeMap::serialize_value
.serde/serde/src/private/ser.rs
Lines 1224 to 1249 in 95b1a5d
This is a problem for
SerializeMap
implementations which only implement theserialize_entry
function (e.g. because the serialized key depends on the value type, as is the case in https://github.com/PistonDevelopers/hematite_nbt where in NBT the value type tag is written to binary before the key is).A "minimal" playground implementation:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5bcbacafdd6927e0f668b71b0d9f6968
I would propose to implement the
FlatMapSerializeMap::serialize_entry
function as follows:As every SerializeMap implementation that implements
serialize_key
andserialize_value
has a default implementation forserialize_entry
there shouldn't be any downsides to implementing this change.The text was updated successfully, but these errors were encountered: