Function combine::parser::repeat::skip_until

source ·
pub fn skip_until<P>(end: P) -> SkipUntil<P>where
    <P::Input as StreamOnce>::Error: ParseError<<P::Input as StreamOnce>::Item, <P::Input as StreamOnce>::Range, <P::Input as StreamOnce>::Position>,
    P: Parser,
Expand description

Skips input until end is encountered or end indicates that it has consumed input before failing (attempt can be used to make it look like it has not consumed any input)

    let mut char_parser = skip_until(char::digit());
    assert_eq!(char_parser.parse("abc123"), Ok(((), "123")));

    let mut byte_parser = skip_until(byte::bytes(&b"TAG"[..]));
    assert_eq!(byte_parser.parse(&b"123TAG"[..]), Ok(((), &b"TAG"[..])));
    assert!(byte_parser.parse(&b"123TATAG"[..]).is_err());

    // `attempt` must be used if the `end` should be consume input before failing
    let mut byte_parser = skip_until(attempt(byte::bytes(&b"TAG"[..])));
    assert_eq!(byte_parser.parse(&b"123TATAG"[..]), Ok(((), &b"TAG"[..])));
}