byte_rb 1.0.4

byte ring buffer
Documentation
  • Coverage
  • 69.23%
    9 out of 13 items documented1 out of 10 items with examples
  • Size
  • Source code size: 18.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jeremyko/byte_rb
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jeremyko

byte_rb

byte ring buffer for rust.

https://crates.io/crates/byte_rb

Documentation

Installation

To use byte_rb, first add this to your Cargo.toml:

[dependencies]

byte_rb = "1"

Or Run the following Cargo command in your project directory:

cargo add byte_rb

Usage

use byte_rb::BrBuffer;

let mut cbuf = BrBuffer::new(6);
println!("{:?}", cbuf);

assert!(cbuf.append(6, b"123456").unwrap());
assert_eq!(cbuf.rpos(), 0);
assert_eq!(cbuf.wpos(), 6);
// "123456"

// Peek at data without changing its internal state.
let result = cbuf.peek(3).unwrap();
assert_eq!(result, b"123");
assert_eq!(cbuf.cumulated_len(), 6);

// Consume data
let result = cbuf.get(3).unwrap();
assert_eq!(result, b"123");
assert_eq!(cbuf.cumulated_len(), 3);
assert_eq!(cbuf.rpos(), 3);
assert_eq!(cbuf.wpos(), 6);
// "  456"

assert!(cbuf.append(3, b"789").unwrap());
assert_eq!(cbuf.cumulated_len(), 6);
assert_eq!(cbuf.rpos(), 3);
assert_eq!(cbuf.wpos(), 3);
// "789456"

let result = cbuf.get(1).unwrap();
assert_eq!(result, b"4");
assert_eq!(cbuf.rpos(), 4);
assert_eq!(cbuf.wpos(), 3);
assert_eq!(cbuf.cumulated_len(), 5);
// "789 56"

let result = cbuf.get(5).unwrap();
assert_eq!(result, b"56789");
assert_eq!(cbuf.rpos(), 3);
assert_eq!(cbuf.wpos(), 3);
assert_eq!(cbuf.cumulated_len(), 0);

assert_eq!(cbuf.capacity(), 6);

License

This project is licensed under the MIT license.