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
impl RestrictedDecodeContext
Sourcepub fn new(min_canonicity: Canonicity) -> Self
pub fn new(min_canonicity: Canonicity) -> Self
Creates a new context with a given minimum canonicity.
Sourcepub fn enter_recursion(&self) -> Self
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
Sourcepub fn limit_reached(&self) -> Result<(), DecodeError>
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.
Sourcepub fn into_inner(self) -> DecodeContext
pub fn into_inner(self) -> DecodeContext
Returns the inner non-restricted context for relaxed decoding.
Sourcepub fn check(&self, canon: Canonicity) -> Result<Canonicity, DecodeError>
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:
- 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
Canonicityvalue. - 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_distinguished2b.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
impl Clone for RestrictedDecodeContext
Source§fn clone(&self) -> RestrictedDecodeContext
fn clone(&self) -> RestrictedDecodeContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more