Function nom::branch::permutation[][src]

pub fn permutation<I: Clone, O, E: ParseError<I>, List: Permutation<I, O, E>>(
    l: List
) -> impl Fn(I) -> IResult<I, O, E>

applies a list of parsers in any order

permutation will succeed if all of the child parsers succeeded. It takes as argument a tuple of parsers, and returns a tuple of the parser results.

use nom::character::complete::{alpha1, digit1};
use nom::branch::permutation;
fn parser(input: &str) -> IResult<&str, (&str, &str)> {
  permutation((alpha1, digit1))(input)
};

// permutation recognizes alphabetic characters then digit
assert_eq!(parser("abc123"), Ok(("", ("abc", "123"))));

// but also in inverse order
assert_eq!(parser("123abc"), Ok(("", ("abc", "123"))));

// it will fail if one of the parsers failed
assert_eq!(parser("abc;"), Err(Err::Error(error_position!(";", ErrorKind::Permutation))));