tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.77k stars 489 forks source link

feat: encode string and bytes slices #979

Open guilload opened 7 months ago

guilload commented 7 months ago

This PR adds the ability to encode &str and &[u8] using string::encode and bytes::encode. This is useful for users writing custom Message implementations who want to avoid unnecessary allocations.

LucioFranco commented 6 months ago

Can you provide some motivation for this change

guilload commented 6 months ago

@morrisonlevi provided some context in his original PR: #978.

My use case is similar. I recently wrote a few custom Message implementations for types with some fields for which I can obtain a &str or &[u8] for free but not a String or Vec<u8> without allocating.

guilload commented 4 months ago

@caspermeijn, is there any chance you can look into this PR?