Trait winnow::Parser

source ·
pub trait Parser<I, O, E> {
Show 19 methods // Required method fn parse_next(&mut self, input: I) -> IResult<I, O, E>; // Provided methods fn by_ref(&mut self) -> ByRef<'_, Self> where Self: Sized { ... } fn value<O2>(self, val: O2) -> Value<Self, O, O2> where Self: Sized, O2: Clone { ... } fn void(self) -> Void<Self, O> where Self: Sized { ... } fn output_into<O2>(self) -> OutputInto<Self, O, O2> where Self: Sized, O: Into<O2> { ... } fn recognize(self) -> Recognize<Self, O> where Self: Sized { ... } fn with_recognized(self) -> WithRecognized<Self, O> where Self: Sized { ... } fn span(self) -> Span<Self, O> where Self: Sized, I: Location + Clone { ... } fn with_span(self) -> WithSpan<Self, O> where Self: Sized, I: Location + Clone { ... } fn map<G, O2>(self, g: G) -> Map<Self, G, O> where G: Fn(O) -> O2, Self: Sized { ... } fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G, O> where Self: Sized, G: FnMut(O) -> Result<O2, E2> { ... } fn verify_map<G, O2>(self, g: G) -> VerifyMap<Self, G, O> where Self: Sized, G: FnMut(O) -> Option<O2> { ... } 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 O: StreamIsPartial, G: Parser<O, O2, E>, Self: Sized { ... } fn parse_to<O2>(self) -> ParseTo<Self, O, O2> where Self: Sized, O: ParseSlice<O2> { ... } fn verify<G, O2: ?Sized>(self, second: G) -> Verify<Self, G, O2> where Self: Sized, G: Fn(&O2) -> bool { ... } fn context<C>(self, context: C) -> Context<Self, O, C> where Self: Sized, C: Clone + Debug, E: ContextError<I, C> { ... } fn complete_err(self) -> CompleteErr<Self> where Self: Sized { ... } fn err_into<E2>(self) -> ErrInto<Self, E, E2> where Self: Sized, E: Into<E2> { ... }
}
Expand description

Core trait for parsing

The simplest way to implement a Parser is with a function

use winnow::prelude::*;

fn success(input: &str) -> IResult<&str, ()> {
    let output = ();
    Ok((input, output))
}

let (input, output) = success.parse_next("Hello").unwrap();
assert_eq!(input, "Hello");  // We didn't consume any input

which can be made stateful by returning a function

use winnow::prelude::*;

fn success<O: Clone>(output: O) -> impl FnMut(&str) -> IResult<&str, O> {
    move |input: &str| {
        let output = output.clone();
        Ok((input, output))
    }
}

let (input, output) = success("World").parse_next("Hello").unwrap();
assert_eq!(input, "Hello");  // We didn't consume any input
assert_eq!(output, "World");

Additionally, some basic types implement Parser as well, including

Required Methods§

source

fn parse_next(&mut self, input: I) -> IResult<I, O, E>

Take tokens from the Stream, turning it into the output

This includes advancing the Stream to the next location.

Provided Methods§

source

fn by_ref(&mut self) -> ByRef<'_, Self>where Self: Sized,

Treat &mut Self as a parser

This helps when needing to move a Parser when all you have is a &mut Parser.

Example

Because parsers are FnMut, they can be called multiple times. This prevents moving f into length_data and g into Parser::complete_err:

pub fn length_value<'i, O, E: ParseError<&'i [u8]>>(
    mut f: impl Parser<&'i [u8], usize, E>,
    mut g: impl Parser<&'i [u8], O, E>
) -> impl FnMut(&'i [u8]) -> IResult<&'i [u8], O, E> {
  move |i: &'i [u8]| {
    let (i, data) = length_data(f).parse_next(i)?;
    let (_, o) = g.complete().parse_next(data)?;
    Ok((i, o))
  }
}

By adding by_ref, we can make this work:

pub fn length_value<'i, O, E: ParseError<&'i [u8]>>(
    mut f: impl Parser<&'i [u8], usize, E>,
    mut g: impl Parser<&'i [u8], O, E>
) -> impl FnMut(&'i [u8]) -> IResult<&'i [u8], O, E> {
  move |i: &'i [u8]| {
    let (i, data) = length_data(f.by_ref()).parse_next(i)?;
    let (_, o) = g.by_ref().complete_err().parse_next(data)?;
    Ok((i, o))
  }
}
source

fn value<O2>(self, val: O2) -> Value<Self, O, O2>where Self: Sized, O2: Clone,

Produce the provided value

Example
use winnow::character::alpha1;

let mut parser = alpha1.value(1234);

assert_eq!(parser.parse_next("abcd"), Ok(("", 1234)));
assert_eq!(parser.parse_next("123abcd;"), Err(ErrMode::Backtrack(Error::new("123abcd;", ErrorKind::Alpha))));
source

fn void(self) -> Void<Self, O>where Self: Sized,

Discards the output of the Parser

Example
use winnow::character::alpha1;

let mut parser = alpha1.void();

assert_eq!(parser.parse_next("abcd"), Ok(("", ())));
assert_eq!(parser.parse_next("123abcd;"), Err(ErrMode::Backtrack(Error::new("123abcd;", ErrorKind::Alpha))));
source

fn output_into<O2>(self) -> OutputInto<Self, O, O2>where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From

Example
use winnow::character::alpha1;

 fn parser1(i: &str) -> IResult<&str, &str> {
   alpha1(i)
 }

 let mut parser2 = parser1.output_into();

// the parser converts the &str output of the child parser into a Vec<u8>
let bytes: IResult<&str, Vec<u8>> = parser2.parse_next("abcd");
assert_eq!(bytes, Ok(("", vec![97, 98, 99, 100])));
source

fn recognize(self) -> Recognize<Self, O>where Self: Sized,

Produce the consumed input as produced value.

Example
use winnow::character::{alpha1};
use winnow::sequence::separated_pair;

let mut parser = separated_pair(alpha1, ',', alpha1).recognize();

assert_eq!(parser.parse_next("abcd,efgh"), Ok(("", "abcd,efgh")));
assert_eq!(parser.parse_next("abcd;"),Err(ErrMode::Backtrack(Error::new(";", ErrorKind::OneOf))));
source

fn with_recognized(self) -> WithRecognized<Self, O>where Self: Sized,

Produce the consumed input with the output

Functions similarly to recognize except it returns the parser output as well.

This can be useful especially in cases where the output is not the same type as the input, or the input is a user defined type.

Returned tuple is of the format (produced output, consumed input).

Example
use winnow::character::{alpha1};
use winnow::bytes::tag;
use winnow::sequence::separated_pair;

fn inner_parser(input: &str) -> IResult<&str, bool> {
    tag("1234").value(true).parse_next(input)
}


let mut consumed_parser = separated_pair(alpha1, ',', alpha1).value(true).with_recognized();

assert_eq!(consumed_parser.parse_next("abcd,efgh1"), Ok(("1", (true, "abcd,efgh"))));
assert_eq!(consumed_parser.parse_next("abcd;"),Err(ErrMode::Backtrack(Error::new(";", ErrorKind::OneOf))));

// the second output (representing the consumed input)
// should be the same as that of the `recognize` parser.
let mut recognize_parser = inner_parser.recognize();
let mut consumed_parser = inner_parser.with_recognized().map(|(output, consumed)| consumed);

assert_eq!(recognize_parser.parse_next("1234"), consumed_parser.parse_next("1234"));
assert_eq!(recognize_parser.parse_next("abcd"), consumed_parser.parse_next("abcd"));
source

fn span(self) -> Span<Self, O>where Self: Sized, I: Location + Clone,

Produce the location of the consumed input as produced value.

Example
use winnow::stream::Located;
use winnow::character::alpha1;
use winnow::sequence::separated_pair;

let mut parser = separated_pair(alpha1.span(), ',', alpha1.span());

assert_eq!(parser.parse_next(Located::new("abcd,efgh")).finish(), Ok((0..4, 5..9)));
assert_eq!(parser.parse_next(Located::new("abcd;")),Err(ErrMode::Backtrack(Error::new(Located::new("abcd;").next_slice(4).0, ErrorKind::OneOf))));
source

fn with_span(self) -> WithSpan<Self, O>where Self: Sized, I: Location + Clone,

Produce the location of consumed input with the output

Functions similarly to Parser::span except it returns the parser output as well.

This can be useful especially in cases where the output is not the same type as the input, or the input is a user defined type.

Returned tuple is of the format (produced output, consumed input).

Example
use winnow::stream::Located;
use winnow::character::alpha1;
use winnow::bytes::tag;
use winnow::sequence::separated_pair;

fn inner_parser(input: Located<&str>) -> IResult<Located<&str>, bool> {
    tag("1234").value(true).parse_next(input)
}


let mut consumed_parser = separated_pair(alpha1.value(1).with_span(), ',', alpha1.value(2).with_span());

assert_eq!(consumed_parser.parse_next(Located::new("abcd,efgh")).finish(), Ok(((1, 0..4), (2, 5..9))));
assert_eq!(consumed_parser.parse_next(Located::new("abcd;")),Err(ErrMode::Backtrack(Error::new(Located::new("abcd;").next_slice(4).0, ErrorKind::OneOf))));

// the second output (representing the consumed input)
// should be the same as that of the `span` parser.
let mut recognize_parser = inner_parser.span();
let mut consumed_parser = inner_parser.with_span().map(|(output, consumed)| consumed);

assert_eq!(recognize_parser.parse_next(Located::new("1234")), consumed_parser.parse_next(Located::new("1234")));
assert_eq!(recognize_parser.parse_next(Located::new("abcd")), consumed_parser.parse_next(Located::new("abcd")));
source

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

Maps a function over the output of a parser

Example
use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult,Parser};
use winnow::character::digit1;

let mut parser = digit1.map(|s: &str| s.len());

// the parser will count how many characters were returned by digit1
assert_eq!(parser.parse_next("123456"), Ok(("", 6)));

// this will fail if digit1 fails
assert_eq!(parser.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Digit))));
source

fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G, O>where Self: Sized, G: FnMut(O) -> Result<O2, E2>,

Applies a function returning a Result over the output of a parser.

Example
use winnow::character::digit1;

let mut parse = digit1.map_res(|s: &str| s.parse::<u8>());

// the parser will convert the result of digit1 to a number
assert_eq!(parse.parse_next("123"), Ok(("", 123)));

// this will fail if digit1 fails
assert_eq!(parse.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Digit))));

// this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
assert_eq!(parse.parse_next("123456"), Err(ErrMode::Backtrack(Error::new("123456", ErrorKind::MapRes))));
source

fn verify_map<G, O2>(self, g: G) -> VerifyMap<Self, G, O>where Self: Sized, G: FnMut(O) -> Option<O2>,

Apply both Parser::verify and Parser::map.

Example
use winnow::character::digit1;

let mut parse = digit1.verify_map(|s: &str| s.parse::<u8>().ok());

// the parser will convert the result of digit1 to a number
assert_eq!(parse.parse_next("123"), Ok(("", 123)));

// this will fail if digit1 fails
assert_eq!(parse.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Digit))));

// this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
assert_eq!(parse.parse_next("123456"), Err(ErrMode::Backtrack(Error::new("123456", ErrorKind::Verify))));
source

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 parser from the output of this one

Example
use winnow::bytes::take;
use winnow::number::u8;

fn length_data(input: &[u8]) -> IResult<&[u8], &[u8]> {
    u8.flat_map(take).parse_next(input)
}

assert_eq!(length_data.parse_next(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
assert_eq!(length_data.parse_next(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(Error::new(&[0, 1, 2][..], ErrorKind::Eof))));

which is the same as

use winnow::bytes::take;
use winnow::number::u8;

fn length_data(input: &[u8]) -> IResult<&[u8], &[u8]> {
    let (input, length) = u8.parse_next(input)?;
    let (input, data) = take(length).parse_next(input)?;
    Ok((input, data))
}

assert_eq!(length_data.parse_next(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
assert_eq!(length_data.parse_next(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(Error::new(&[0, 1, 2][..], ErrorKind::Eof))));
source

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

Applies a second parser over the output of the first one

Example
use winnow::character::digit1;
use winnow::bytes::take;

let mut digits = take(5u8).and_then(digit1);

assert_eq!(digits.parse_next("12345"), Ok(("", "12345")));
assert_eq!(digits.parse_next("123ab"), Ok(("", "123")));
assert_eq!(digits.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Eof))));
source

fn parse_to<O2>(self) -> ParseTo<Self, O, O2>where Self: Sized, O: ParseSlice<O2>,

Apply std::str::FromStr to the output of the parser

Example
use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult,Parser};
use winnow::character::digit1;

fn parser(input: &str) -> IResult<&str, u64> {
    digit1.parse_to().parse_next(input)
}

// the parser will count how many characters were returned by digit1
assert_eq!(parser.parse_next("123456"), Ok(("", 123456)));

// this will fail if digit1 fails
assert_eq!(parser.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Digit))));
source

fn verify<G, O2: ?Sized>(self, second: G) -> Verify<Self, G, O2>where Self: Sized, G: Fn(&O2) -> bool,

Returns the output of the child parser if it satisfies a verification function.

The verification function takes as argument a reference to the output of the parser.

Example

let mut parser = alpha1.verify(|s: &str| s.len() == 4);

assert_eq!(parser.parse_next("abcd"), Ok(("", "abcd")));
assert_eq!(parser.parse_next("abcde"), Err(ErrMode::Backtrack(Error::new("abcde", ErrorKind::Verify))));
assert_eq!(parser.parse_next("123abcd;"),Err(ErrMode::Backtrack(Error::new("123abcd;", ErrorKind::Alpha))));
source

fn context<C>(self, context: C) -> Context<Self, O, C>where Self: Sized, C: Clone + Debug, E: ContextError<I, C>,

If parsing fails, add context to the error

This is used mainly to add user friendly information to errors when backtracking through a parse tree.

source

fn complete_err(self) -> CompleteErr<Self>where Self: Sized,

Transforms Incomplete into Backtrack

Example

let mut parser = take(5u8).complete_err();

assert_eq!(parser.parse_next(Partial::new("abcdefg")), Ok((Partial::new("fg"), "abcde")));
assert_eq!(parser.parse_next(Partial::new("abcd")), Err(ErrMode::Backtrack(Error::new(Partial::new("abcd"), ErrorKind::Complete))));
source

fn err_into<E2>(self) -> ErrInto<Self, E, E2>where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From

Trait Implementations§

source§

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

Available on crate feature alloc only.
source§

fn parse_next(&mut self, input: I) -> IResult<I, O, E>

Take tokens from the Stream, turning it into the output Read more
source§

fn by_ref(&mut self) -> ByRef<'_, Self>where Self: Sized,

Treat &mut Self as a parser Read more
source§

fn value<O2>(self, val: O2) -> Value<Self, O, O2>where Self: Sized, O2: Clone,

Produce the provided value Read more
source§

fn void(self) -> Void<Self, O>where Self: Sized,

Discards the output of the Parser Read more
source§

fn output_into<O2>(self) -> OutputInto<Self, O, O2>where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From Read more
source§

fn recognize(self) -> Recognize<Self, O>where Self: Sized,

Produce the consumed input as produced value. Read more
source§

fn with_recognized(self) -> WithRecognized<Self, O>where Self: Sized,

Produce the consumed input with the output Read more
source§

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

Maps a function over the output of a parser Read more
source§

fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G, O>where Self: Sized, G: FnMut(O) -> Result<O2, E2>,

Applies a function returning a Result over the output of a parser. Read more
source§

fn verify_map<G, O2>(self, g: G) -> VerifyMap<Self, G, O>where Self: Sized, G: FnMut(O) -> Option<O2>,

source§

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 parser from the output of this one Read more
source§

fn parse_to<O2>(self) -> ParseTo<Self, O, O2>where Self: Sized, O: ParseSlice<O2>,

Apply std::str::FromStr to the output of the parser Read more
source§

fn verify<G, O2: ?Sized>(self, second: G) -> Verify<Self, G, O2>where Self: Sized, G: Fn(&O2) -> bool,

Returns the output of the child parser if it satisfies a verification function. Read more
source§

fn context<C>(self, context: C) -> Context<Self, O, C>where Self: Sized, C: Clone + Debug, E: ContextError<I, C>,

If parsing fails, add context to the error Read more
source§

fn complete_err(self) -> CompleteErr<Self>where Self: Sized,

source§

fn err_into<E2>(self) -> ErrInto<Self, E, E2>where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From

Implementations on Foreign Types§

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>,

source§

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

Available on crate feature alloc only.
source§

fn parse_next(&mut self, input: I) -> IResult<I, O, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, E: ParseError<I>, P1, P2, P3, P4, P5, P6> Parser<I, (O1, O2, O3, O4, O5, O6), E> for (P1, P2, P3, P4, P5, P6)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>, P19: Parser<I, O19, E>, P20: Parser<I, O20, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20, O21, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20, O21), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>, P19: Parser<I, O19, E>, P20: Parser<I, O20, E>, P21: Parser<I, O21, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7> Parser<I, (O1, O2, O3, O4, O5, O6, O7), E> for (P1, P2, P3, P4, P5, P6, P7)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>,

source§

impl<I, O1, O2, E: ParseError<I>, P1, P2> Parser<I, (O1, O2), E> for (P1, P2)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>,

source§

fn parse_next(&mut self, i: I) -> IResult<I, (O1, O2), E>

source§

impl<I, O1, O2, O3, O4, O5, E: ParseError<I>, P1, P2, P3, P4, P5> Parser<I, (O1, O2, O3, O4, O5), E> for (P1, P2, P3, P4, P5)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>,

source§

fn parse_next(&mut self, i: I) -> IResult<I, (O1, O2, O3, O4, O5), E>

source§

impl<I, E> Parser<I, u8, E> for u8where I: StreamIsPartial + Stream<Token = u8>, E: ParseError<I>,

This is a shortcut for one_of.

Example

fn parser(i: &[u8]) -> IResult<&[u8], u8> {
    b'a'.parse_next(i)
}
assert_eq!(parser(&b"abc"[..]), Ok((&b"bc"[..], b'a')));
assert_eq!(parser(&b" abc"[..]), Err(ErrMode::Backtrack(Error::new(&b" abc"[..], ErrorKind::OneOf))));
assert_eq!(parser(&b"bc"[..]), Err(ErrMode::Backtrack(Error::new(&b"bc"[..], ErrorKind::OneOf))));
assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&b""[..], ErrorKind::OneOf))));
source§

fn parse_next(&mut self, i: I) -> IResult<I, u8, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8), E> for (P1, P2, P3, P4, P5, P6, P7, P8)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>,

source§

impl<I, O1, E: ParseError<I>, P1> Parser<I, (O1,), E> for (P1,)where P1: Parser<I, O1, E>,

source§

fn parse_next(&mut self, i: I) -> IResult<I, (O1,), E>

source§

impl<I, O1, O2, O3, O4, E: ParseError<I>, P1, P2, P3, P4> Parser<I, (O1, O2, O3, O4), E> for (P1, P2, P3, P4)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>,

source§

fn parse_next(&mut self, i: I) -> IResult<I, (O1, O2, O3, O4), E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>, P19: Parser<I, O19, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>,

source§

impl<'s, I, E: ParseError<I>> Parser<I, <I as Stream>::Slice, E> for &'s [u8]where I: Compare<&'s [u8]> + StreamIsPartial + Stream,

This is a shortcut for tag.

Example


fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
  alt((&"Hello"[..], take(5usize))).parse_next(s)
}

assert_eq!(parser(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
assert_eq!(parser(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
assert_eq!(parser(&b"Some"[..]), Err(ErrMode::Backtrack(Error::new(&b"Some"[..], ErrorKind::Eof))));
assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&b""[..], ErrorKind::Eof))));
source§

fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Slice, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>,

source§

impl<I, E> Parser<I, <I as Stream>::Token, E> for charwhere I: StreamIsPartial + Stream, <I as Stream>::Token: AsChar + Copy, E: ParseError<I>,

This is a shortcut for one_of.

Example

fn parser(i: &str) -> IResult<&str, char> {
    'a'.parse_next(i)
}
assert_eq!(parser("abc"), Ok(("bc", 'a')));
assert_eq!(parser(" abc"), Err(ErrMode::Backtrack(Error::new(" abc", ErrorKind::OneOf))));
assert_eq!(parser("bc"), Err(ErrMode::Backtrack(Error::new("bc", ErrorKind::OneOf))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::OneOf))));
source§

fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Token, E>

source§

impl<'s, I, E: ParseError<I>, const N: usize> Parser<I, <I as Stream>::Slice, E> for &'s [u8; N]where I: Compare<&'s [u8; N]> + StreamIsPartial + Stream,

This is a shortcut for tag.

Example


fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
  alt((b"Hello", take(5usize))).parse_next(s)
}

assert_eq!(parser(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
assert_eq!(parser(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
assert_eq!(parser(&b"Some"[..]), Err(ErrMode::Backtrack(Error::new(&b"Some"[..], ErrorKind::Eof))));
assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&b""[..], ErrorKind::Eof))));
source§

fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Slice, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>,

source§

impl<I, E: ParseError<I>> Parser<I, (), E> for ()

source§

fn parse_next(&mut self, i: I) -> IResult<I, (), E>

source§

impl<I, O1, O2, O3, E: ParseError<I>, P1, P2, P3> Parser<I, (O1, O2, O3), E> for (P1, P2, P3)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>,

source§

fn parse_next(&mut self, i: I) -> IResult<I, (O1, O2, O3), E>

source§

impl<'s, I, E: ParseError<I>> Parser<I, <I as Stream>::Slice, E> for &'s strwhere I: Compare<&'s str> + StreamIsPartial + Stream,

This is a shortcut for tag.

Example


fn parser(s: &str) -> IResult<&str, &str> {
  alt(("Hello", take(5usize))).parse_next(s)
}

assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser("Something"), Ok(("hing", "Somet")));
assert_eq!(parser("Some"), Err(ErrMode::Backtrack(Error::new("Some", ErrorKind::Eof))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Eof))));
source§

fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Slice, E>

Implementors§

source§

impl<'a, I, O, E, F> Parser<I, O, E> for Fwhere F: FnMut(I) -> IResult<I, O, E> + 'a,

source§

impl<'p, I, O, E, P: Parser<I, O, E>> Parser<I, O, E> for ByRef<'p, P>

source§

impl<F, I, O, E> Parser<I, O, E> for CompleteErr<F>where I: Stream, F: Parser<I, O, E>, E: ParseError<I>,

source§

impl<I, O1, O2, E, E2, F, G> Parser<I, O2, E> for MapRes<F, G, O1>where I: Clone, F: Parser<I, O1, E>, G: FnMut(O1) -> Result<O2, E2>, E: FromExternalError<I, E2>,

source§

impl<I, O1, O2, E, F, G> Parser<I, O1, E> for Verify<F, G, O2>where I: Clone, E: ParseError<I>, F: Parser<I, O1, E>, G: Fn(&O2) -> bool, O1: Borrow<O2>, O2: ?Sized,

source§

impl<I, O1, O2, E, F, G> Parser<I, O2, E> for VerifyMap<F, G, O1>where I: Clone, F: Parser<I, O1, E>, G: FnMut(O1) -> Option<O2>, E: ParseError<I>,

source§

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

source§

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

source§

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

source§

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

source§

impl<I, O1, O2, E, P> Parser<I, O2, E> for ParseTo<P, O1, O2>where I: Stream, O1: ParseSlice<O2>, E: ParseError<I>, P: Parser<I, O1, E>,

source§

impl<I, O1, O2: Clone, E: ParseError<I>, F: Parser<I, O1, E>> Parser<I, O2, E> for Value<F, O1, O2>

source§

impl<I, O, E, F> Parser<I, <I as Stream>::Slice, E> for Recognize<F, O>where I: Stream + Offset, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F> Parser<I, (O, <I as Stream>::Slice), E> for WithRecognized<F, O>where I: Stream + Offset, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F> Parser<I, (O, Range<usize>), E> for WithSpan<F, O>where I: Clone + Location, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F> Parser<I, Range<usize>, E> for Span<F, O>where I: Clone + Location, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F, C> Parser<I, O, E> for Context<F, O, C>where I: Stream, C: Clone + Debug, E: ContextError<I, C>, F: Parser<I, O, E>,

source§

impl<I, O, E: ParseError<I>, F: Parser<I, O, E>> Parser<I, (), E> for Void<F, O>

source§

impl<I: Clone, O1, O2, E, F: Parser<I, O1, E>> Parser<I, O2, E> for OutputInto<F, O1, O2>where O1: Into<O2>,

source§

impl<I: Clone, O, E1, E2: ParseError<I>, F: Parser<I, O, E1>> Parser<I, O, E2> for ErrInto<F, E1, E2>where E1: Into<E2>,

source§

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