Crates.io | byte_rb |
lib.rs | byte_rb |
version | 1.0.4 |
source | src |
created_at | 2023-02-25 02:31:56.837829 |
updated_at | 2023-03-27 15:44:27.865269 |
description | byte ring buffer |
homepage | |
repository | https://github.com/jeremyko/byte_rb |
max_upload_size | |
id | 794103 |
size | 18,928 |
byte ring buffer for rust.
https://crates.io/crates/byte_rb
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
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);
This project is licensed under the MIT license.