nom::number

Function u8

Source
pub fn u8<I, E: ParseError<I>>() -> impl Parser<I, Output = u8, Error = E>
where I: Input<Item = u8>,
Expand description

Recognizes an unsigned 1 byte integer

Note that endianness does not apply to 1 byte numbers.

use nom::number::u8;

let parser = |s| {
  u8::<_, (_, ErrorKind)>().parse(s)
};

assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));