ParseLimits

Struct ParseLimits 

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

Resource limits applied while parsing untrusted bencode.

Implementations§

Source§

impl ParseLimits

Source

pub const fn new( max_depth: usize, max_items: usize, max_byte_string_length: usize, max_total_input: usize, max_owned_allocation: usize, ) -> Self

Creates a complete parser limit configuration.

Source

pub const fn max_depth(self) -> usize

Returns the maximum container nesting depth.

Source

pub const fn max_items(self) -> usize

Returns the maximum number of parsed values.

Source

pub const fn max_byte_string_length(self) -> usize

Returns the maximum byte-string length.

Source

pub const fn max_integer_digits(self) -> usize

Returns the maximum number of integer digits, excluding a minus sign.

Source

pub const fn with_max_integer_digits(self, maximum: usize) -> Self

Replaces the maximum integer digit count.

Source

pub const fn max_total_input(self) -> usize

Returns the maximum total input length.

Source

pub const fn max_owned_allocation(self) -> usize

Returns the maximum budget for allocations made by owned conversion.

Source

pub const fn check_depth(self, actual: usize) -> Result<()>

Checks a nesting depth against the configured maximum.

§Errors

Returns a resource-limit error when actual exceeds the maximum depth.

Source

pub const fn check_items(self, actual: usize) -> Result<()>

Checks an item count against the configured maximum.

§Errors

Returns a resource-limit error when actual exceeds the maximum count.

Source

pub const fn check_byte_string_length(self, actual: usize) -> Result<()>

Checks a byte-string length against the configured maximum.

§Errors

Returns a resource-limit error when actual exceeds the maximum length.

Source

pub const fn check_integer_digits(self, actual: usize) -> Result<()>

Checks an integer digit count against the configured maximum.

§Errors

Returns a resource-limit error when actual exceeds the maximum count.

Source

pub const fn check_total_input(self, actual: usize) -> Result<()>

Checks total input length against the configured maximum.

§Errors

Returns a resource-limit error when actual exceeds the input maximum.

Source

pub const fn checked_owned_allocation( self, current: usize, added: usize, ) -> Result<usize>

Adds an allocation to an accumulated total without overflow.

§Errors

Returns a resource-limit error when addition overflows or the resulting total exceeds the owned-allocation budget.

Trait Implementations§

Source§

impl Clone for ParseLimits

Source§

fn clone(&self) -> ParseLimits

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ParseLimits

Source§

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

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

impl Default for ParseLimits

Source§

fn default() -> Self

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

impl PartialEq for ParseLimits

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ParseLimits

Source§

impl Eq for ParseLimits

Source§

impl StructuralPartialEq for ParseLimits

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.