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
merged 1 commit into from Feb 2, 2020
Merged

replace serialize key,value functions by serialize_entry #614

merged 1 commit into from Feb 2, 2020

Conversation

jmfiaschi
Copy link
Contributor

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 :
https://docs.serde.rs/src/serde/ser/mod.rs.html#1778-1784
/// 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 : https://docs.serde.rs/src/serde/ser/mod.rs.html#1798-1826

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 dtolnay merged commit 1059dc3 into serde-rs:master Feb 2, 2020
@dtolnay
Copy link
Member

dtolnay commented Feb 2, 2020

Thanks, published in 1.0.46.

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

Successfully merging this pull request may close these issues.

None yet

2 participants