Function parse_parser

Source
pub fn parse_parser<Ctx, P: Parser<Ctx>>(
    input: &str,
    ctx: Ctx,
) -> Result<P::Value, ParseError<'_>>
Expand description

Parsers a value from an input string using an explicitly specified parser

This function takes an input string slice as an input and a context, and returns a value parsed from the input or an error. parse ensures that all tokens from the input string were consumed, and the input is valid.

This function is different from parse in that is expects a parser as its second generic parameter. The value returned by parse_parser does not need to implement Parsable. parse_parser most commonly used with custom parsers.

ยงExample:

use cmdparse::parse_parser;
use cmdparse::parsers::{IntegerParser, StringParser, tuples::TupleParser2};

type ExplicitParser = TupleParser2<IntegerParser<u64>, StringParser>;
let value = parse_parser::<_, ExplicitParser>("42 fourty-two", ())?;
assert_eq!(value, (42, "fourty-two".to_string()));