Expand description
A simplified implementation of the bytes
crate, with different features, less safety.
The crate is currently minimalist rather than maximalist, and for example does not support
methods on BytesMut
that seem like they should be safe, because they are not yet needed.
For example, BytesMut
should be able to implement Send
, and BytesMut::extract_to
could
return a BytesMut
rather than a Bytes
.
§Examples
use timely_bytes::arc::BytesMut;
let bytes = vec![0u8; 1024];
let mut shared1 = BytesMut::from(bytes);
let mut shared2 = shared1.extract_to(100);
let mut shared3 = shared1.extract_to(100);
let mut shared4 = shared2.extract_to(60);
assert_eq!(shared1.len(), 824);
assert_eq!(shared2.len(), 40);
assert_eq!(shared3.len(), 100);
assert_eq!(shared4.len(), 60);
for byte in shared1.iter_mut() { *byte = 1u8; }
// memory in slabs [4, 2, 3, 1]: merge back in arbitrary order.
shared2.try_merge(shared3).ok().expect("Failed to merge 2 and 3");
shared2.try_merge(shared1.freeze()).ok().expect("Failed to merge 23 and 1");
shared4.try_merge(shared2).ok().expect("Failed to merge 4 and 231");
assert_eq!(shared4.len(), 1024);
Modules§
- An
Arc
-backed mutable byte slice backed by a common allocation.