Function parser_compose::byte

source ·
pub fn byte(range: RangeInclusive<u8>) -> Byte
Expand description

Returns a parser that recognizes the first byte in a byte slice if its value is in the specified range

The range must be bounded on both ends. Only inclusive ranges are allowed

use parser_compose::{Parser, byte};

let msg = &[0, 1][..];

let zero = byte(0..=0);
let (value, rest) = zero.try_parse(msg).unwrap();

assert_eq!(value, [0]);
assert_eq!(rest, [1]);

let result = zero.try_parse(rest);
assert!(result.is_err());