Function parser_compose::ascii_str

source ·
pub fn ascii_str(range: RangeInclusive<u8>) -> AsciiStr
Expand description

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

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

Note: that the first byte in a string slice might not be valid unicode. Only use this if the thing you are parsing is limited to the ASCII character set.

use parser_compose::{Parser, ascii_str};

let msg = "a1";

let alphabetic = ascii_str(97..=122);
let (value, rest) = alphabetic.try_parse(msg.into()).unwrap();

assert_eq!(value, "a");
assert_eq!(rest, "1");

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