rust-analyzer / rowan

Apache License 2.0
697 stars 57 forks source link

Avoid temporary allocation in Serialize implementations #30

Closed CAD97 closed 4 years ago

CAD97 commented 4 years ago

Fixes these FIXMEs:

https://github.com/rust-analyzer/rowan/blob/a00ccb60ea99eccbc7f24d31ee83e925e0d8258d/src/serde_impls.rs#L14-L15 https://github.com/rust-analyzer/rowan/blob/a00ccb60ea99eccbc7f24d31ee83e925e0d8258d/src/serde_impls.rs#L28-L29

This necessarily uses two wrapper types: one to delegate to Serializer::collect_str, and since that uses Display, one to implement Display by forwarding to Debug.

The benefit is that any data format serializer that specializes collect_str (such as serde_json) will now be able to skip the temporary String allocation.

matklad commented 4 years ago

bors r+

bors[bot] commented 4 years ago

Build succeeded