Skip to main content

parse

Function parse 

Source
pub fn parse<'a>(
    value: &'a [u8],
    limits: &Limits,
) -> Result<RangeHeader<'a>, ParseError>
Expand description

Parses range-unit "=" range-set (RFC 9110 section 14.1.2).

The unit compares case-insensitively. A bytes set must hold only first-last, first-, and -length specs; another unit’s set is checked as other-range bytes and not interpreted.

§Errors

ErrorKind::NotToken for the unit; ErrorKind::InvalidRange for a missing =, whitespace around it, an empty set, first > last, or a malformed spec; ErrorKind::InvalidNumber; a control kind for a control byte; the list errors. A position past u64::MAX is not an error: it saturates (RFC 9110 section 14.1.2), which is past the end of any representation.

§Examples

use parse_net::{range, Limits, RangeSpec};

let h = range::parse(b"bytes=0-0, -5, 10-", &Limits::DEFAULT)?;
assert_eq!(h.specs().collect::<Vec<_>>(), [RangeSpec::FromTo(0, 0), RangeSpec::Suffix(5), RangeSpec::From(10)]);
assert!(range::parse(b"bytes=5-4", &Limits::DEFAULT).is_err());