Function winnow::character::newline

source ·
pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>where
    I: StreamIsPartial + Stream,
    <I as Stream>::Token: AsChar + Copy,
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(input: &str) -> IResult<&str, char> {
    newline(input)
}

assert_eq!(parser("\nc"), Ok(("c", '\n')));
assert_eq!(parser("\r\nc"), Err(ErrMode::Backtrack(Error::new("\r\nc", ErrorKind::Verify))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
assert_eq!(newline::<_, Error<_>>(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
assert_eq!(newline::<_, Error<_>>(Partial::new("\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("\r\nc"), ErrorKind::Verify))));
assert_eq!(newline::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));