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
impl Limits
Sourcepub const fn builder() -> LimitsBuilder
pub const fn builder() -> LimitsBuilder
Returns a builder for the limits (see LimitsBuilder).
Sourcepub const fn into_builder(self) -> LimitsBuilder
pub const fn into_builder(self) -> LimitsBuilder
Returns a builder that starts with these limits.
Sourcepub const fn set_max_depth(&mut self, depth: usize)
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.
Sourcepub const fn max_depth(&self) -> Option<usize>
pub const fn max_depth(&self) -> Option<usize>
Returns the limit of the nesting depth of maps and sequences.
Sourcepub const fn set_max_events(&mut self, events: usize)
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.
Sourcepub const fn max_events(&self) -> Option<usize>
pub const fn max_events(&self) -> Option<usize>
Returns the limit of the total number of events.
Sourcepub const fn set_max_items(&mut self, items: usize)
pub const fn set_max_items(&mut self, items: usize)
Limits the number of items in a sequence and entries in a map.
Sourcepub const fn max_items(&self) -> Option<usize>
pub const fn max_items(&self) -> Option<usize>
Returns the limit of the number of items in a sequence and entries in a map.
Sourcepub const fn set_max_len(&mut self, len: usize)
pub const fn set_max_len(&mut self, len: usize)
Limits the length of strings and bytes (in bytes).
Trait Implementations§
impl Copy for Limits
impl Eq for Limits
impl StructuralPartialEq for Limits
Auto Trait Implementations§
impl Freeze for Limits
impl RefUnwindSafe for Limits
impl Send for Limits
impl Sync for Limits
impl Unpin for Limits
impl UnsafeUnpin for Limits
impl UnwindSafe for Limits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.