Skip to main content

Limits

Struct Limits 

Source
pub struct Limits { /* private fields */ }
Expand description

The work and size bounds every parser enforces.

Every bound is checked before the work it governs, and none allocates: they bound loops. The defaults meet every minimum RFC 9651 section 3 sets for parsers, so a conforming sender is never refused by default.

BoundDefaultSource
list members1024RFC 9651 section 3.1 minimum
inner list members256RFC 9651 section 3.1.1 minimum
parameters per item or field256RFC 9651 section 3.1.2 minimum
dictionary members1024RFC 9651 section 3.2 minimum
key length256RFC 9651 minimum is 64
string length (decoded)1024RFC 9651 section 3.3.3 minimum
token length512RFC 9651 section 3.3.4 minimum
byte sequence length (decoded)16384RFC 9651 section 3.3.5 minimum
empty list elements16RFC 9110 section 5.6.1.2: “a reasonable number”
comment depth8none in the RFC
ranges16RFC 9110 section 14.2 permits refusal
RFC 2231 sections32none in the RFC
encoded words per field64none in the RFC
forwarded hops16none in the RFC

A setter may set a bound below the RFC minimum: that is the caller tightening deliberately, and it makes the parser non-conforming for that field.

§Examples

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

const STRICT: Limits = Limits::DEFAULT.max_list_members(64).max_params(16);
let err = list::parse(b"a, b, c", &Limits::DEFAULT.max_list_members(2)).unwrap_err();
assert_eq!((err.kind(), err.offset()), (ErrorKind::TooManyMembers, 6));

Implementations§

Source§

impl Limits

Source

pub const DEFAULT: Self

The defaults in the table above.

Source

pub const fn new() -> Self

The defaults; the same as Limits::DEFAULT.

Source

pub const fn max_list_members(self, n: u16) -> Self

The most members a list may have (default 1024).

Source

pub const fn max_inner_list_members(self, n: u16) -> Self

The most members a Structured Field inner list may have (default 256).

Source

pub const fn max_params(self, n: u16) -> Self

The most parameters an item or a field may have (default 256).

Source

pub const fn max_dictionary_members(self, n: u16) -> Self

The most members a Structured Field dictionary may have (default 1024).

Source

pub const fn max_key_len(self, n: u16) -> Self

The longest Structured Field key (default 256).

Source

pub const fn max_string_len(self, n: u16) -> Self

The longest Structured Field string, decoded (default 1024).

Source

pub const fn max_token_len(self, n: u16) -> Self

The longest Structured Field token (default 512).

Source

pub const fn max_byte_seq_len(self, n: u32) -> Self

The longest Structured Field byte sequence, decoded (default 16384).

Source

pub const fn max_empty_elements(self, n: u16) -> Self

The most empty list elements accepted in one field (default 16).

Source

pub const fn max_comment_depth(self, n: u8) -> Self

The deepest comment nesting accepted (default 8).

Source

pub const fn max_ranges(self, n: u16) -> Self

The most ranges a Range field may request (default 16).

Source

pub const fn max_rfc2231_sections(self, n: u8) -> Self

The most RFC 2231 sections in one parameter (default 32). Values above 32, the size of the reassembly array, are stored as 32.

Source

pub const fn max_encoded_words(self, n: u16) -> Self

The most RFC 2047 encoded words in one field (default 64).

Source

pub const fn max_hops(self, n: u8) -> Self

The most hops in a forwarded chain (default 16).

Source

pub const fn allow_leap_second(self, yes: bool) -> Self

Whether HTTP-date accepts second 60 (read as 59). Off by default.

Source

pub const fn duplicate_params(self, p: DuplicatePolicy) -> Self

What parameter parsers do with a repeated name (default DuplicatePolicy::Refuse).

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Limits

Source§

impl Debug for Limits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Limits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Limits

Source§

impl Hash for Limits

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Limits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.