byteloaf 0.2.0

Use a heap-allocated byte buffer (a 'loaf') via independently owned, accessed, and moved slices.
Documentation
  • Coverage
  • 4%
    1 out of 25 items documented0 out of 18 items with examples
  • Size
  • Source code size: 30.18 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 457.24 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sirkibsirkib/byteloaf
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sirkibsirkib

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 = LoafPart::new(5);
let slice = x.as_slice_mut();

slice.write_all(b"hello").unwrap();
assert_eq!(slice, b"hello");

slice[3] = b'Q';
assert_eq!(slice, b"helQo");

Ownership of the loaf's bytes can be further sub-divided by splitting existing parts.

let y = x.split_at(3);
assert_eq!(x.as_slice(), b"hel"  );
assert_eq!(y.as_slice(),    b"lo");

For parts owning contiguous bytes, their sub-division of ownership can be re-drawn, or joined into one part.

x.with_try_resplit_at(y, 0..4).unwrap();
assert_eq!(x.as_slice(), b"hell" );
assert_eq!(y.as_slice(),     b"o");
let z = x.with_try_join(y).unwrap();
assert_eq!(z.as_slice(), b"hello");

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.