Crates.io | peek-buffer |
lib.rs | peek-buffer |
version | 0.1.2 |
source | src |
created_at | 2024-06-20 06:44:49.365304 |
updated_at | 2024-06-20 07:06:42.359797 |
description | Generic-typed buffer with ability to peek into the future! (And the past too.) |
homepage | https://github.com/ay0ks/peek-buffer |
repository | https://github.com/ay0ks/peek-buffer |
max_upload_size | |
id | 1277610 |
size | 45,310 |
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());