Skip to main content

Limits

Struct Limits 

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

Limits the size of the deserialized data (a value of the Context).

Deser does not use the stack to process nested data, so deeply nested input cannot overflow the stack during deserialization. Still it can be useful to limit the size of untrusted input, as the values that are deserialized might be processed recursively later, or to limit the memory used. All limits are off by default.

The limits are configured in the context, for instance in the configuration of a format:

use deser::de::Limits;
use deser::Context;

let config = deser_json::DeserializerConfig::builder()
    .context(Context::with(Limits::builder().max_depth(1).build()))
    .build();
let err = config.from_str::<Vec<Vec<u32>>>("[[1]]").unwrap_err();
assert_eq!(
    err.to_string(),
    "LimitExceeded: recursion limit exceeded at line 1 column 2"
);

The DeserializeDriver enforces the limits of its context (see set_context). They see the events as the sinks receive them, after all Layers, so their errors have the context that layers add (for instance the path).

Implementations§

Source§

impl Limits

Source

pub const fn new() -> Limits

Creates limits that limit nothing.

Source

pub const fn builder() -> LimitsBuilder

Returns a builder for the limits (see LimitsBuilder).

Source

pub const fn into_builder(self) -> LimitsBuilder

Returns a builder that starts with these limits.

Source

pub const fn set_max_depth(&mut self, depth: usize)

Limits the nesting depth of maps and sequences.

With a depth of 1, maps and sequences cannot contain other maps and sequences.

Source

pub const fn max_depth(&self) -> Option<usize>

Returns the limit of the nesting depth of maps and sequences.

Source

pub const fn set_max_events(&mut self, events: usize)

Limits the total number of events.

Every atom and every start and end of a map or sequence counts.

Source

pub const fn max_events(&self) -> Option<usize>

Returns the limit of the total number of events.

Source

pub const fn set_max_items(&mut self, items: usize)

Limits the number of items in a sequence and entries in a map.

Source

pub const fn max_items(&self) -> Option<usize>

Returns the limit of the number of items in a sequence and entries in a map.

Source

pub const fn set_max_len(&mut self, len: usize)

Limits the length of strings and bytes (in bytes).

Source

pub const fn max_len(&self) -> Option<usize>

Returns the limit of the length of strings and bytes (in bytes).

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 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.