Giter Site home page Giter Site logo

circbuf-rs's Introduction

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

circbuf-rs's People

Contributors

novara754 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.