Re:Rust: Not So Great For Codec Implementing
by tatterdemalion on Tuesday August 01, 2017 @01:25PM
(#14903117)
Bytes is intended for use with the tokio ecoystem where you cna't use references often because borrowing across a yield point in a future would be a lifetime error.
Re:Rust: Not So Great For Codec Implementing
by valarauca1 on Tuesday August 01, 2017 @02:09PM
(#14903592)
Can't `Vec<u8>` serve the same purpose?
Re:Rust: Not So Great For Codec Implementing
by tatterdemalion on Tuesday August 01, 2017 @03:58PM
(#14904714)
Then you have to do a deep clone every time. Arc<Vec<u8>> is also not sufficient, because Bytes lets you share a reference count among slices to different offset into the buffer.
Re:Rust: Not So Great For Codec Implementing
by dbaupp on Tuesday August 01, 2017 @01:46PM
(#14903351)
Being an ARC backed array isn't like std::string, and I don't see why having that copy-on-write behaviour implies it is fundamental. Could you expand?
Re:Rust: Not So Great For Codec Implementing
by wuch on Tuesday August 01, 2017 @02:11PM
(#14903612)
In pre C++11 it was quite typical for std::string to be implemented with COW semantics.
Since C++11 standard it is no longer permitted, though it is not necessarily reflected in all stdlib implementations.
Re:Rust: Not So Great For Codec Implementing
by valarauca1 on Tuesday August 01, 2017 @02:09PM
(#14903585)
This is my mistake. I assumed shared pointer semantics and applied it to the wrong type :\
Bytes is basically just C++'s `std::string` (kind of don't bite my head off people who've memorized the C++17 standard). Its an ARC backed array [1]. This suggests it should be a fairly fundamental abstraction.
Edit: ^^^My C++ is wrong sorry :(
Really I disagree with its purpose. In its immutable, non-threaded safe form you can create the same structure by just borrowing a value. This ofc requires making your peace with the borrow checker and `Cow<'a, T>` copy on write types.
By in large Bytes advertised purpose is network code. And for networking code its really only _super_ useful if your using a Packet Ring in Linux. As jemalloc will not return regularly re-allocated buffers.
Really this is all performance theater. How you manage/architect your socket reads/writes will have an order of magnitude larger effect then what abstraction you _store_ those bytes in once read.
[1] https://carllerche.github.io/bytes/bytes/struct.Bytes.htm