10000 GitHub - novara754/circbuf-rs: Basic circular buffer library for Rust.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

novara754/circbuf-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI

circbuf

Basic circular buffer library for Rust.

Example

use circbuf::CircBuf;

fn main() {
    // Create a new circular buffer that can hold 16 elements
    let mut buf = CircBuf::<i32, 16>::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

About

Basic circular buffer library for Rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0