nyst/
lib.rs

1/// Pre-built parsers for convenience.
2pub mod parser;
3
4/// Generic parser trait.
5/// Only `Output` and `parse` need to be defined to apply the trait.
6pub trait Parser {
7    type Input;
8    type Output;
9    /// Parse `data`, and return a `ParseResult`.
10    fn parse(&self, data: &[Self::Input]) -> ParseResult<Self::Output>;
11}
12
13/// A wrapper around `Result` with `ParseError` as the error.
14pub type ParseResult<T> = Result<(T, usize), ParseError>;
15
16/// A container for all the different possible errors when parsing.
17#[derive(Debug, PartialEq)]
18pub enum ParseError {
19    InvalidData,
20    NotEnoughData,
21    Other(&'static str),
22}
23
24/// Includes all of the necessary traits for working with nyst.
25pub mod prelude {
26    pub use super::{ParseError, ParseResult, Parser};
27}