Skip to main content

digits_range

Function digits_range 

Source
pub fn digits_range<U: UnsignedInteger, const MIN: u128, const MAX: u128>(
    range: RangeInclusive<U>,
) -> DigitsRange<U, MIN, MAX>
Expand description

Leaf parser for unsigned numbers, reading only digits matching the supplied range.

This can be faster than number_range for ranges with a small number of digits, but unlike the normal number parsers it does not check for trailing digits. It should be followed by a parser that wouldn’t match digits to ensure the number is in the intended range.

MIN and MAX must match the supplied range, and all numbers with as many digits as MAX must fit in the unsigned type.

See also parser::digits_range!.

§Examples

let parser = parser::digits_range::<_, 1, 12>(1u32..=12);
assert_eq!(parser.parse(b"07-21"), Ok((7, &b"-21"[..])));
assert_eq!(parser.parse(b"123"), Ok((12, &b"3"[..])));
assert!(parser.parse(b"13-21").is_err());