pub enum DecodeFailure<E> {
#[non_exhaustive] Incomplete {
source: Option<E>,
required_total: NonZeroUsize,
},
#[non_exhaustive] Invalid {
source: E,
consumed: Option<NonZeroUsize>,
},
}Expand description
Failure reported by crate::Codec::decode.
This type separates stream-control failures from codec-domain failures.
Incomplete tells buffered adapters to preserve the
current input tail and request more units. Invalid
carries the codec-specific malformed, non-canonical, or otherwise invalid
input error with a known non-zero consumption length, or with unknown
consumption when set to None.
§Type Parameters
E: Codec-specific invalid-input error type.
Variants§
#[non_exhaustive]Incomplete
The visible input is a valid prefix but not enough to decode a value.
Fields
This variant is marked as non-exhaustive
source: Option<E>Codec-specific context for the incomplete prefix, when available.
Stream drivers may ignore this field while retrying input. Once the stream reaches EOF, adapters can use it to preserve detailed diagnostics instead of reconstructing an error from the length bound alone.
required_total: NonZeroUsizeCurrent non-zero minimum total units required before retrying from the value start.
A later retry may raise this lower bound after the codec sees a longer prefix.
#[non_exhaustive]Invalid
The input is invalid for the codec.
Fields
This variant is marked as non-exhaustive
source: ECodec-specific invalid-input error.
consumed: Option<NonZeroUsize>Invalid units that may be consumed by a non-strict policy, when known.
Implementations§
Source§impl<E> DecodeFailure<E>
impl<E> DecodeFailure<E>
Sourcepub const fn incomplete(required_total: NonZeroUsize) -> Self
pub const fn incomplete(required_total: NonZeroUsize) -> Self
Sourcepub const fn incomplete_with_source(
source: E,
required_total: NonZeroUsize,
) -> Self
pub const fn incomplete_with_source( source: E, required_total: NonZeroUsize, ) -> Self
Creates an incomplete-input decode failure with codec-specific context.
§Parameters
source: Codec-specific error describing the visible incomplete prefix.required_total: Current non-zero minimum units required before retrying from the value start.
§Returns
Returns an incomplete decode failure retaining source for adapters
that need detailed EOF diagnostics.
Sourcepub const fn invalid(source: E, consumed: NonZeroUsize) -> Self
pub const fn invalid(source: E, consumed: NonZeroUsize) -> Self
Sourcepub const fn invalid_unknown(source: E) -> Self
pub const fn invalid_unknown(source: E) -> Self
Sourcepub const fn required_total(&self) -> Option<NonZeroUsize>
pub const fn required_total(&self) -> Option<NonZeroUsize>
Returns the current minimum input length required before retrying an incomplete prefix.
§Returns
Returns Some(required_total) for incomplete failures, where the value
is a lower bound that a later retry may raise, or None for
invalid-input failures.
Sourcepub const fn incomplete_source(&self) -> Option<&E>
pub const fn incomplete_source(&self) -> Option<&E>
Borrows the codec-specific error retained for an incomplete prefix.
§Returns
Returns Some(source) when the codec supplied incomplete-input context,
or None when the failure only carries the retry bound.
Sourcepub const fn invalid_source(&self) -> Option<&E>
pub const fn invalid_source(&self) -> Option<&E>
Borrows the codec-specific invalid-input error.
§Returns
Returns Some(source) for invalid-input failures, or None for
incomplete failures.
Sourcepub const fn consumed_units(&self) -> Option<NonZeroUsize>
pub const fn consumed_units(&self) -> Option<NonZeroUsize>
Trait Implementations§
Source§impl<E: Clone> Clone for DecodeFailure<E>
impl<E: Clone> Clone for DecodeFailure<E>
Source§fn clone(&self) -> DecodeFailure<E>
fn clone(&self) -> DecodeFailure<E>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more