Giter Site home page Giter Site logo

kana-rus / byte_reader Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 42.38 MB

A minimal byte-by-byte reader for parsing input

Home Page: https://crates.io/crates/byte_reader

License: MIT License

Rust 100.00%
byte byte-array bytes lightweight minimal parse parser parsing reader simple

byte_reader's Introduction

byte_reader

A minimal byte-by-byte reader for parsing input.

test status of byte_reader crates.io

Use case

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}`.");
}

Operations

  • remaining
  • read_while, read_until
  • next, next_if
  • peek, peek2, peek3
  • advance_by, unwind_by
  • consume, consume_oneof
  • skip_while, skip_whitespace

Features

"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_by
  • read_uint, read_int
  • read_camel, read_snake, read_kebab

License

byte_reader is licensed under the MIT License (LICENSE or https://opensource.org/licenses/MIT).

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.