| Crates.io | byte_reader |
| lib.rs | byte_reader |
| version | 3.1.1 |
| created_at | 2023-09-19 17:40:41.358624+00 |
| updated_at | 2024-07-08 21:54:49.823153+00 |
| description | A minimal byte-by-byte reader for parsing input |
| homepage | https://crates.io/crates/byte_reader |
| repository | https://github.com/kana-rus/byte_reader |
| max_upload_size | |
| id | 977086 |
| size | 13,796 |
A minimal byte-by-byte reader for parsing input.
Following situation:
I want to read and parse some input, but it's not so large-scale parsing task, so I'd like to avoid adding a heavyweight crate like nom or nom8 to my
dependencies...
Of course, byte_reader supports no std environment.
use byte_reader::Reader;
fn main() {
// Get an input `&[u8]` from a File, standard input, or others
let sample_input = "Hello, byte_reader!".as_bytes();
// Create mutable `r` for the input
let mut r = Reader::new(sample_input);
// Use some simple operations
// to parse the input
r.consume("Hello").unwrap();
r.consume(",").unwrap();
r.skip_whitespace();
let name = r.read_while(|b| b != &b'!'); // b"byte_reader"
let name = String::from_utf8_lossy(name).to_string();
r.consume("!").unwrap();
println!("Greeted to `{name}`.");
}
remainingread_while, read_untilnext, next_ifpeek, peek2, peek3advance_by, unwind_byconsume, consume_oneofskip_while, skip_whitespace"location"Enable tracking reader's location, line and column (1-origin), in the input bytes.
"text"Some utility methods for text-parsing are availableļ¼
read_quoted_byread_uint, read_intread_camel, read_snake, read_kebabbyte_reader is licensed under the MIT License (LICENSE or https://opensource.org/licenses/MIT).