rotating-buffer

Crates.iorotating-buffer
lib.rsrotating-buffer
version0.2.0
sourcesrc
created_at2021-06-15 18:36:44.683293
updated_at2021-06-15 18:36:44.683293
descriptionSmall helper data structure that allows retaining unused data
homepage
repositoryhttps://ghom.niij.org/eaon/rotating_buffer
max_upload_size
id410568
size8,990
(eaon)

documentation

README

Rotating Buffer

… is a small helper data structure that allows a stack-allocated buffer to be reused while keeping data that couldn't be handled immediately.

Example:

use rotating_buffer::*;
let mut buf = RotatingBuffer::<u8, 4>::new();

buf.get_append_only().copy_from_slice(&[1, 2, 3, 4]);
buf.add_len(4);
assert_eq!(&[1, 2, 3, 4], buf.as_slice());

buf.rotate_right_and_resize_at(3);
assert_eq!(&[4], buf.as_slice());

assert_eq!(3, buf.get_append_only().len());
buf.get_append_only().copy_from_slice(&[5, 6, 7]);
buf.add_len(3);
assert_eq!(&[4, 5, 6, 7], buf.as_slice());

buf.rotate_right_and_resize_at(4);
assert_eq!(buf.as_slice().len(), 0);

Inspired by a pairing session at Recurse Center 👩‍💻🐙

Commit count: 0

cargo fmt