Function winnow::combinator::empty

source ·
pub fn empty<Input, Error>(_input: &mut Input) -> PResult<(), Error>
where Input: Stream, Error: ParserError<Input>,
Expand description

Succeed, consuming no input

For example, it can be used as the last alternative in alt to specify the default case.

Useful with:

Note: This never advances the Stream

§Example

use winnow::combinator::alt;
use winnow::combinator::empty;

fn sign(input: &str) -> IResult<&str, isize> {
    alt((
        '-'.value(-1),
        '+'.value(1),
        empty.value(1)
    )).parse_peek(input)
}
assert_eq!(sign("+10"), Ok(("10", 1)));
assert_eq!(sign("-10"), Ok(("10", -1)));
assert_eq!(sign("10"), Ok(("10", 1)));