Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/novara754/circbuf-rs
Basic circular buffer library for Rust.
https://github.com/novara754/circbuf-rs
Last synced: about 2 months ago
JSON representation
Basic circular buffer library for Rust.
- Host: GitHub
- URL: https://github.com/novara754/circbuf-rs
- Owner: novara754
- License: mit
- Created: 2021-05-04T13:35:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-22T12:56:17.000Z (over 2 years ago)
- Last Synced: 2024-10-14T22:14:27.822Z (3 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![CI](https://github.com/vzwGrey/circbuf-rs/actions/workflows/ci.yaml/badge.svg)](https://github.com/vzwGrey/circbuf-rs/actions/workflows/ci.yaml)
# circbuf
Basic [circular buffer](https://en.wikipedia.org/wiki/Circular_buffer) library for Rust.
## Example
```rust
use circbuf::CircBuf;fn main() {
// Create a new circular buffer that can hold 16 elements
let mut buf = CircBuf::::new();
// Fill the buffer completely
for i in 0..16 {
buf.push(i);
}
assert!(buf.is_full());// Iterate over values
for n in buf.iter() {
println!("{}", n);
}// Adding values when the buffer is full overwrites the oldest value
for i in 16..19 {
buf.push(i);
}// Iterate over values again
for n in buf.iter() {
println!("{}", n);
}// Index specific values
println!("buf[0] = {}", buf[0]);
// println!("buf[20] = {}", buf[20]); // panic when index invalid// Delete values while the buffer is not empty
while !buf.is_empty() {
// Popped values are returned in Option
println!("{}", buf.pop().unwrap());
}// Check number of elements in a buffer
assert_eq!(buf.len(), 0);
}
```## License
Licensed under the [MIT License](./LICENSE)