Skip to main content

Parser

Trait Parser 

pub trait Parser<I, O, E> {
    // Required method
    fn parse(&mut self, input: I) -> Result<(I, O), Err<E>>;

    // Provided methods
    fn map<G, O2>(self, g: G) -> Map<Self, G, O>
       where G: Fn(O) -> O2,
             Self: Sized { ... }
    fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
       where G: FnMut(O) -> H,
             H: Parser<I, O2, E>,
             Self: Sized { ... }
    fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
       where G: Parser<O, O2, E>,
             Self: Sized { ... }
    fn and<G, O2>(self, g: G) -> And<Self, G>
       where G: Parser<I, O2, E>,
             Self: Sized { ... }
    fn or<G>(self, g: G) -> Or<Self, G>
       where G: Parser<I, O, E>,
             Self: Sized { ... }
    fn into<O2, E2>(self) -> Into<Self, O, O2, E, E2>
       where O2: From<O>,
             E2: From<E>,
             Self: Sized { ... }
}
Available on crate feature rustls only.
Expand description

All nom parsers implement this trait

Required Methods§

fn parse(&mut self, input: I) -> Result<(I, O), Err<E>>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error

Provided Methods§

fn map<G, O2>(self, g: G) -> Map<Self, G, O>
where G: Fn(O) -> O2, Self: Sized,

Maps a function over the result of a parser

fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
where G: FnMut(O) -> H, H: Parser<I, O2, E>, Self: Sized,

Creates a second parser from the output of the first one, then apply over the rest of the input

fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
where G: Parser<O, O2, E>, Self: Sized,

Applies a second parser over the output of the first one

fn and<G, O2>(self, g: G) -> And<Self, G>
where G: Parser<I, O2, E>, Self: Sized,

Applies a second parser after the first one, return their results as a tuple

fn or<G>(self, g: G) -> Or<Self, G>
where G: Parser<I, O, E>, Self: Sized,

Applies a second parser over the input if the first one failed

fn into<O2, E2>(self) -> Into<Self, O, O2, E, E2>
where O2: From<O>, E2: From<E>, Self: Sized,

automatically converts the parser’s output and error values to another type, as long as they implement the From trait

Trait Implementations§

§

impl<'a, I, O, E> Parser<I, O, E> for Box<dyn Parser<I, O, E> + 'a>

Available on crate feature alloc only.
§

fn parse(&mut self, input: I) -> Result<(I, O), Err<E>>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error
§

fn map<G, O2>(self, g: G) -> Map<Self, G, O>
where G: Fn(O) -> O2, Self: Sized,

Maps a function over the result of a parser
§

fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
where G: FnMut(O) -> H, H: Parser<I, O2, E>, Self: Sized,

Creates a second parser from the output of the first one, then apply over the rest of the input
§

fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
where G: Parser<O, O2, E>, Self: Sized,

Applies a second parser over the output of the first one
§

fn and<G, O2>(self, g: G) -> And<Self, G>
where G: Parser<I, O2, E>, Self: Sized,

Applies a second parser after the first one, return their results as a tuple
§

fn or<G>(self, g: G) -> Or<Self, G>
where G: Parser<I, O, E>, Self: Sized,

Applies a second parser over the input if the first one failed
§

fn into<O2, E2>(self) -> Into<Self, O, O2, E, E2>
where O2: From<O>, E2: From<E>, Self: Sized,

automatically converts the parser’s output and error values to another type, as long as they implement the From trait

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl<'a> Parser<&'a [u8], TbsCertificate<'a>, X509Error> for TbsCertificateParser

§

impl<'a> Parser<&'a [u8], X509Certificate<'a>, X509Error> for X509CertificateParser

§

impl<'a> Parser<&'a [u8], X509Extension<'a>, X509Error> for X509ExtensionParser

§

impl<'a, I, O1, O2, E1, E2, F> Parser<I, O2, E2> for Into<F, O1, O2, E1, E2>
where I: Clone, O2: From<O1>, E2: ParseError<I> + From<E1>, F: Parser<I, O1, E1>,

§

impl<'a, I, O1, O2, E, F, G> Parser<I, (O1, O2), E> for And<F, G>
where F: Parser<I, O1, E>, G: Parser<I, O2, E>,

§

impl<'a, I, O1, O2, E, F, G> Parser<I, O2, E> for AndThen<F, G, O1>
where F: Parser<I, O1, E>, G: Parser<O1, O2, E>,

§

impl<'a, I, O1, O2, E, F, G> Parser<I, O2, E> for Map<F, G, O1>
where F: Parser<I, O1, E>, G: Fn(O1) -> O2,

§

impl<'a, I, O1, O2, E, F, G, H> Parser<I, O2, E> for FlatMap<F, G, O1>
where F: Parser<I, O1, E>, G: Fn(O1) -> H, H: Parser<I, O2, E>,

§

impl<'a, I, O, E> Parser<I, O, E> for Box<dyn Parser<I, O, E> + 'a>

Available on crate feature alloc only.
§

impl<'a, I, O, E, F> Parser<I, O, E> for F
where F: FnMut(I) -> Result<(I, O), Err<E>> + 'a,

§

impl<'a, I, O, E, F, G> Parser<I, O, E> for Or<F, G>
where I: Clone, E: ParseError<I>, F: Parser<I, O, E>, G: Parser<I, O, E>,