winnow::ascii

Function crlf

Source
pub fn crlf<Input, Error>(
    input: &mut Input,
) -> PResult<<Input as Stream>::Slice, Error>
where Input: StreamIsPartial + Stream + Compare<&'static str>, Error: ParserError<Input>,
Expand description

Recognizes the string "\r\n".

Complete version: Will return an error if there’s not enough input data.

[Partial version][crate::_topic::partial]: Will return Err(winnow::error::ErrMode::Incomplete(_)) if there’s not enough input data.

§Effective Signature

Assuming you are parsing a &str Stream:

pub fn crlf<'i>(input: &mut &'i str) -> PResult<&'i str>

§Example

fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
    crlf.parse_next(input)
}

assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));