Byte Loaf 🍞
What
This library lets one treat a heap-allocated byte buffer as a loaf of bread 🍞; its contents can be arbitrarily partitioned into slices, which can be passed around, accessed, and owned independently.
Concretely, a single-part loaf can be created, and treated as a mutable byte buffer as usual.
let x = new;
let slice = x.as_slice_mut;
slice.write_all.unwrap;
assert_eq!;
slice = b'Q';
assert_eq!;
Ownership of the loaf's bytes can be further sub-divided by splitting existing parts.
let y = x.split_at;
assert_eq!;
assert_eq!;
For parts owning contiguous bytes, their sub-division of ownership can be re-drawn, or joined into one part.
x.with_try_resplit_at.unwrap;
assert_eq!;
assert_eq!;
let z = x.with_try_join.unwrap;
assert_eq!;
Why
This library was created as a utility for storing independently-owned byte slices, while minimizing the number of heap allocations. For example, this is useful for hanging onto the contents of sent UDP datagrams until their receipt is acknowledged later.