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
...
```rust use byte_reader::Reader;
fn main() {
// Get an input from a File, standard input, or another source
// Input can be &str
, String
, &[u8]
, or Vec<u8>
let sampleinput = "Hello, bytereader!";
// Create mutable `r`
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_snake().unwrap(); // byte_reader
r.consume("!").unwrap();
println!("Greeted to `{name}`.");
} ```
advance_by
, unwind_by
next
, next_if
peek
, peek2
, peek3
consume
, consume_oneof
skip_while
, skip_whitespace
read_while
read_uint
, read_int
read_string
, read_string_unchecked
read_camel
, read_snake
, read_kebab
"location"
You can track the reader's parsing location ( line and column ) in the input bytes.
```rust /* enable "location" feature */ use byte_reader::Reader;
fn main() { let mut r = Reader::new("Hello, byte_reader!");
r.consume("Hello").unwrap();
r.consume(",").unwrap();
r.skip_whitespace();
let name_line = r.line; // 1
let name_column = r.column; // 11
let name = r.read_snake().unwrap(); // byte_reader
r.consume("!").unwrap();
println!("Greeted to `{name}`.");
println!("In the input, the name starts at column {name_column} of line {name_line}");
} ```