Skip to main content

RestrictedDecodeContext

Struct RestrictedDecodeContext 

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

Additional information passed to every distinguished decode/merge function.

The context should be passed by value and can be freely cloned. When passing to a function which is decoding a nested object, then use enter_recursion.

Implementations§

Source§

impl RestrictedDecodeContext

Source

pub fn new(min_canonicity: Canonicity) -> Self

Creates a new context with a given minimum canonicity.

Source

pub fn enter_recursion(&self) -> Self

Call this function before recursively decoding.

There is no exit function since this function creates a new DecodeContext to be used at the next level of recursion. Continue to use the old context

Source

pub fn limit_reached(&self) -> Result<(), DecodeError>

Checks whether the recursion limit has been reached in the stack of decodes described by the DecodeContext at self.ctx.

Returns Ok<()> if it is ok to continue recursing. Returns Err<DecodeError> if the recursion limit has been reached.

Source

pub fn into_inner(self) -> DecodeContext

Returns the inner non-restricted context for relaxed decoding.

Source

pub fn check(&self, canon: Canonicity) -> Result<Canonicity, DecodeError>

Checks the given canonicity against the minimum constraint that this context has.

This must be called and checked at a few specific times, whenever the canonicity is (possibly) being reduced and it hasn’t already been checked by some source that returned that canonicity value:

  1. When decoding, and a non-canonical state is observed (such as a value that is represented in a non-canonical form, or an unknown field in the encoding), this can be called with a literal Canonicity value.
  2. After calling one of the distinguished helper trait methods that does not have a restricted context in its parameters to check against, and therefore could not possibly have converted a non-canonical state into an error yet: 2a. DistinguishedProxiable::decode_proxy_distinguished 2b. DistinguishedCollection::insert_distinguished

After these canonicity values have been checked, and at all other times, it should be safe to directly update the canonicity that an implementation will itself return since each value it receives should already be tolerated by the context.

Trait Implementations§

Source§

impl Clone for RestrictedDecodeContext

Source§

fn clone(&self) -> RestrictedDecodeContext

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 RestrictedDecodeContext

Source§

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

Formats the value using the given formatter. Read more

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