bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Confusing documentation around `Arc<[u8]>` compatibility

Open BTOdell opened this issue 1 year ago • 3 comments

The latest documentation of the crate reads:

For Bytes implementations which point to a reference counted shared storage (e.g. an Arc<[u8]>),
sharing will be implemented by increasing the reference count.

Reference: https://docs.rs/bytes/latest/bytes/struct.Bytes.html#sharing

This lead me to assume that Bytes should provide a from conversion function from an Arc<[u8]> to a Bytes instance where the backing storage is an Arc. However, it doesn't appear that this from function exists.

I don't think it's a good idea for documentation to reference imaginary scenarios that aren't implemented by the library as it sets up false expectations with regard to how the library works and what features it provides.

BTOdell avatar Mar 27 '24 08:03 BTOdell

It in fact quite useful, but it should do a better job at being compatible

Sytten avatar Apr 12 '24 16:04 Sytten

Would an implementation for From<Arc<[u8]>> for Bytes using Bytes::from_owner be accepted? I'm willing to create a PR.

bschoenmaeckers avatar Jun 20 '25 14:06 bschoenmaeckers

Using Bytes::from_owner would create a new refcount not use the one from the arc.

Darksonn avatar Jun 20 '25 21:06 Darksonn