peek-buffer

Crates.iopeek-buffer
lib.rspeek-buffer
version0.1.2
sourcesrc
created_at2024-06-20 06:44:49.365304
updated_at2024-06-20 07:06:42.359797
descriptionGeneric-typed buffer with ability to peek into the future! (And the past too.)
homepagehttps://github.com/ay0ks/peek-buffer
repositoryhttps://github.com/ay0ks/peek-buffer
max_upload_size
id1277610
size45,310
Dimitriy (ay0ks)

documentation

README

peek-buffer Crates.io Version docs.rs


Essential for parsing.

let mut buffer = PeekBuffer::from("Hello, World!");

// peek without consuming
while let Some(&c) = buffer.peek() {
    println!("{}", c);

    // advance to the next item (char in this situation)
    buffer.advance_char();
    // generally you should use buffer.advance() to move to the next element
    // but if you're parsing a string, you should use buffer.advance_char()
    // since it keeps track of the line and the column the cursor is at.
}

// peek with consuming
buffer.rewind_to_beginning();
while let Some(&c) = buffer.eat() {
    println!("{}", c);
    buffer.advance_char();
}

println!("{}", buffer.len());
Commit count: 11

cargo fmt