Skip to content
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

replace serialize key,value functions by serialize_entry #614

merged 1 commit into from Feb 2, 2020

replace serialize key,value functions by serialize_entry #614

merged 1 commit into from Feb 2, 2020


Copy link

@jmfiaschi jmfiaschi commented Feb 2, 2020

The purpuse is to serialize serde_json::Map<> with other serializer like serde-xml-rs::to_writer(&mut writer, &json_value) that is not possible today. The problem is serde_json use only map.serialize_key(k) and map.serialize_key(v). Some serializer can use only map.serialize_entry(k, v). If we follow these advices :
/// Serialize a map key.
/// If possible, Serialize implementations are encouraged to use
/// serialize_entry instead as it may be implemented more efficiently in
/// some formats compared to a pair of calls to serialize_key and
/// serialize_value.
and the implementation of serialize_entry :

We should use during the Map serialize use serialize_entry function instead of serialize_key/serialize_key and use them into serialize_entry.

call serialize_key/value into serialize_entry
@jmfiaschi jmfiaschi changed the title remplace serialize key,value functions by serialize_entry replace serialize key,value functions by serialize_entry Feb 2, 2020
dtolnay approved these changes Feb 2, 2020
@dtolnay dtolnay merged commit 1059dc3 into serde-rs:master Feb 2, 2020
1 check passed
Copy link

dtolnay commented Feb 2, 2020

Thanks, published in 1.0.46.

@jmfiaschi jmfiaschi deleted the map-serialize-entry branch Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants