pub fn newline<I, Error: ParserError<I>>(input: &mut I) -> PResult<char, Error>
Expand description
Matches a newline character '\n'
.
Complete version: Will return an error if there’s not enough input data.
Partial version: Will return Err(winnow::error::ErrMode::Incomplete(_))
if there’s not enough input data.
§Example
fn parser<'s>(input: &mut &'s str) -> PResult<char, InputError<&'s str>> {
newline.parse_next(input)
}
assert_eq!(parser.parse_peek("\nc"), Ok(("c", '\n')));
assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Verify))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Verify))));
assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));