tokio-rs / bytes

Utilities for working with bytes
MIT License
1.86k stars 278 forks source link

BytesMut::zeroed doc header improvement #713

Closed juliusl closed 2 months ago

juliusl commented 2 months ago

It would be great if the doc header included a note:

/// Creates a new `BytesMut`, which is initialized with zero.
///  
/// **Note**: The length of the buffer will be set to `len`

It's easy to miss that the argument is len which corresponds to the actual len, was scratching my head a bunch until I added sanity checks to discover this.

Darksonn commented 2 months ago

What did you confuse the length with? I know that there is a common mistake where people incorrectly assume that with_capacity returns a value with a non-zero length, but that doesn't seem to be the case you ran into.

paolobarbolini commented 2 months ago

I've opened #714 to try to make the docs a bit more specific.

juliusl commented 2 months ago

What did you confuse the length with? I know that there is a common mistake where people incorrectly assume that with_capacity returns a value with a non-zero length, but that doesn't seem to be the case you ran into.

I was expecting the same behavior as with_capacity and new initially and I'm okay that it's not the same behavior but thinking it would be nice if it were more obvious.

Thanks @paolobarbolini !