You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am relatively new to Rust but already had to deal with in-memory buffers for binary data. I noticed that one could use &[u8] or Vec<u8> for that. However, I also noticed there is bytes::Bytes, which sounds promising as it bothered to give a name to that concept.
Unfortunately, using it was a bit cumbersome, as I had a hard time to to convince all involved modules to just accept Bytes. That might be totally due to me, as I am still novice, though. Anyhow, I wondered whether the fuzz is worth it.
Is there a resource explaining when one should opt to bytes::Bytes and when there are no benefits compared to Vec<u8>? It might be opinionated, but I would love to learn about when it would provide some benefits.
In case there is no such resource, I would like to suggest that a brief section could be added to the documentation.
The text was updated successfully, but these errors were encountered:
The primary feature of Bytes is that the .clone() operation is really cheap. A clone on a Bytes just increments a counter for how many clones there are, whereas cloning a Vec<u8> copies all of the data in the vector. It is comparable to an Arc<Vec<u8>>, except that Bytes supports slicing so that you only see part of the buffer.
I am relatively new to Rust but already had to deal with in-memory buffers for binary data. I noticed that one could use
&[u8]
orVec<u8>
for that. However, I also noticed there isbytes::Bytes
, which sounds promising as it bothered to give a name to that concept.Unfortunately, using it was a bit cumbersome, as I had a hard time to to convince all involved modules to just accept Bytes. That might be totally due to me, as I am still novice, though. Anyhow, I wondered whether the fuzz is worth it.
Is there a resource explaining when one should opt to
bytes::Bytes
and when there are no benefits compared toVec<u8>
? It might be opinionated, but I would love to learn about when it would provide some benefits.In case there is no such resource, I would like to suggest that a brief section could be added to the documentation.
The text was updated successfully, but these errors were encountered: