Skip to main content

DecodeBudget

Struct DecodeBudget 

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

Running counters for a single decode. Construct one per decode call.

Implementations§

Source§

impl DecodeBudget

Source

pub fn new(limits: DecodeLimits) -> Self

Create a fresh budget with zeroed counters for the given limits.

Source

pub fn limits(&self) -> DecodeLimits

The DecodeLimits this budget enforces.

Source

pub fn check_input_bytes(&self, codec: CodecId, len: usize) -> Result<()>

Check input size against DecodeLimits::max_input_bytes.

Source

pub fn check_tokens(&self, codec: CodecId, count: usize) -> Result<()>

Check token count against DecodeLimits::max_tokens.

Source

pub fn check_collection_len(&self, codec: CodecId, len: usize) -> Result<()>

Check collection length against DecodeLimits::max_collection_len.

Source

pub fn check_string_bytes(&self, codec: CodecId, len: usize) -> Result<()>

Check string length against DecodeLimits::max_string_bytes.

Source

pub fn check_blob_bytes(&self, codec: CodecId, len: usize) -> Result<()>

Check blob length against DecodeLimits::max_blob_bytes.

Source

pub fn add_trivia(&mut self, codec: CodecId) -> Result<()>

Charge one trivia item and check the running total against DecodeLimits::max_trivia_items.

Source

pub fn enter_node(&mut self, codec: CodecId, depth: usize) -> Result<()>

Charge one Expr node and check both the running node count against DecodeLimits::max_expr_nodes and depth against DecodeLimits::max_depth.

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> 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, 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.