bparse 0.29.2

A library for parsing bytes
Documentation
#![warn(missing_docs)]
//! ## Overview
//!
//! Parsing usually involves going through a sequence of bytes and branching off based on what was seen.
//! This crate simplifies the task of recognizing complex patterns in a byte slices.
//!
//! It is made up of three parts:
//! 1. The [`Pattern`] trait: represents the pattern to be recognized.
//! 1. A list of common functions and combinators for composing `Patterns` together.
//! 1. The [`Buf`] struct; a [`Cursor`](std::io::Cursor)-like wrapper around an input slice that uses patterns to advance its position.
//!
//! # Example
//!
//! Recognizing JSON numbers can get tricky.
//! The [spec](https://www.json.org/json-en.html) allows for numbers like  `12`, `-398.42`, and even `12.4e-3`.
//! Here we incrementally build up a pattern called `number` that can recognizes all JSON number forms.
//!
//! ```
//! use bparse::{Buf, Pattern, range, at_least, optional, oneof, end};
//!
//! let sign = optional(oneof(b"-+"));
//! let onenine = range(b'1', b'9');
//! let digit = "0".or(onenine);
//! let digits = at_least(1, digit);
//! let fraction = optional(".".then(digits));
//! let exponent = optional("E".then(sign).then(digits).or("e".then(sign).then(digits)));
//! let integer = onenine
//!     .then(digits)
//!     .or("-".then(onenine).then(digits))
//!     .or("-".then(digit))
//!     .or(digit);
//! let number = integer.then(fraction).then(exponent);
//!
//! let input = "234||344.5||0.43e12";
//!
//! let mut buf = Buf::from(input);
//!
//! let Some(b"234") = buf.consume(number) else {
//!     panic!();
//! };
//!
//! assert!(buf.skip("||"));
//!
//! let Some(b"344.5") = buf.consume(number) else {
//!     panic!();
//! };
//!
//! assert!(buf.skip("||"));
//!
//! let Some(b"0.43e12") = buf.consume(number) else {
//!     panic!();
//! };
//!
//! assert!(buf.consume(end()).is_some());
//! ```

mod buf;
mod pattern;

pub use buf::Buf;
pub use pattern::*;

#[cfg(doctest)]
#[doc = include_str!("../README.md")]
pub struct ReadmeDocTests;