Crate timely_bytes
source ·Expand description
A simplified implementation of the bytes
crate, with different features, less safety.
§Examples
use timely_bytes::arc::Bytes;
let bytes = vec![0u8; 1024];
let mut shared1 = Bytes::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; }
for byte in shared2.iter_mut() { *byte = 2u8; }
for byte in shared3.iter_mut() { *byte = 3u8; }
for byte in shared4.iter_mut() { *byte = 4u8; }
// 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).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.