Function winnow::bytes::complete::tag

source ·
pub fn tag<T, I, Error: ParseError<I>>(
    tag: T
) -> impl Fn(I) -> IResult<I, <I as Stream>::Slice, Error>where
    I: Stream + Compare<T>,
    T: SliceLen + Clone,
👎Deprecated since 0.1.0: Replaced with <code>winnow::bytes::tag</code>
Expand description

Recognizes a pattern

The input data will be compared to the tag combinator’s argument and will return the part of the input that matches the argument

It will return Err(ErrMode::Backtrack((_, ErrorKind::Tag))) if the input doesn’t match the pattern

Example

use winnow::bytes::complete::tag;

fn parser(s: &str) -> IResult<&str, &str> {
  tag("Hello")(s)
}

assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser("Something"), Err(ErrMode::Backtrack(Error::new("Something", ErrorKind::Tag))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));

WARNING: Deprecated, replaced with winnow::bytes::tag