Function winnow::ascii::newline

source ·
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][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 newline(input: &mut &str) -> PResult<char>

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::Tag))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
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::Tag))));
assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));