LengthDelimitedCodec
could support encoding borrowed buffers
#6116
Labels
A-tokio-util
Area: The tokio-util crate
C-feature-request
Category: A feature request.
M-codec
Module: tokio-util/codec
S-breaking-change
A breaking change that requires manual coordination to be released.
Is your feature request related to a problem? Please describe.
Consider this code:
This allocation is unneeded.
impl Encoder<Bytes> for LengthDelimitedCodec
just reslicessrc
, soimpl<'a> Encoder<&'a [u8]> for LengthDelimitedCodec
is just as possible.Describe the solution you'd like
I first thought that just adding the missing impl would be enough, but unfortunately having two
Encoder<_>
impls breaks type inference, so this is a backwards incompatible change, oh well.Some possible options:
Make it opt-in via some kind of type tag, i.e.
All the existing methods would have to be implemented on the
<Bytes>
variant.<&[u8]>
variant would need new methods like::new_borrowed()
or something.Make a wrapper type.
Just wait for the next breaking release and break it then.
Describe alternatives you've considered
Don’t do it. Cases like the above one will continue to require unneccesary allocation, which is kind of sad, but not world-ending.
Additional context
I’m willing to send a PR if some possible path of solution is accepted.
The text was updated successfully, but these errors were encountered: