1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// Pre-built parsers for convenience.
pub mod parser;

/// Generic parser trait.
/// Only `Output` and `parse` need to be defined to apply the trait.
pub trait Parser {
    type Input;
    type Output;
    /// Parse `data`, and return a `ParseResult`.
    fn parse(&self, data: &[Self::Input]) -> ParseResult<Self::Output>;
}

/// A wrapper around `Result` with `ParseError` as the error.
pub type ParseResult<T> = Result<(T, usize), ParseError>;

/// A container for all the different possible errors when parsing.
#[derive(Debug, PartialEq)]
pub enum ParseError {
    InvalidData,
    NotEnoughData,
    Other(&'static str),
}

/// Includes all of the necessary traits for working with nyst.
pub mod prelude {
    pub use super::{ParseError, ParseResult, Parser};
}