Skip to main content

parse

Function parse 

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

Parses parameters at the start of s.

s starts at the first ; (optionally preceded by OWS) or is empty. Parsing continues as long as the grammar does; the view and the number of bytes used are returned (OWS after the last parameter is not used), and whatever follows is the caller’s to check. Empty parameters (;;, a trailing ;) are allowed, as the grammar says. Whitespace around = is not (BWS is not part of this grammar).

§Errors

ErrorKind::NotToken for a bad name; ErrorKind::MissingValue for a name with no = or no value; ErrorKind::InvalidByte for whitespace around =; the quoted-string errors; ErrorKind::DuplicateParameter under DuplicatePolicy::Refuse; ErrorKind::TooManyMembers beyond Limits::max_params.

§Examples

use parse_net::{param, ErrorKind, Limits};

let dup = param::parse(b";a=1;A=2", &Limits::DEFAULT).unwrap_err();
assert_eq!((dup.kind(), dup.offset()), (ErrorKind::DuplicateParameter, 5));
assert_eq!(param::parse(b";a =1", &Limits::DEFAULT).unwrap_err().kind(), ErrorKind::InvalidByte);