pub struct CodecValueDecoder<C>where
C: Codec,{ /* private fields */ }Expand description
Decodes one encoded unit slice into one owned value by using a Codec.
CodecValueDecoder is the default bridge from the low-level unchecked
Codec contract to the convenience-layer ValueDecoder contract. The
supplied input slice must contain exactly one encoded value. After a
successful decode, the adapter calls Codec::decode_flush to reset
decode-side stream state for the next call.
§Type Parameters
C: Low-level codec used to decode one value.
Implementations§
Source§impl<C> CodecValueDecoder<C>where
C: Codec,
impl<C> CodecValueDecoder<C>where
C: Codec,
Sourcepub fn new(codec: C) -> Self
pub fn new(codec: C) -> Self
Creates a decoder backed by codec.
§Parameters
codec: Low-level codec used to decode one value.
§Returns
Returns a value decoder adapter for the supplied codec.
§Panics
In debug builds, panics when the supplied codec violates the
Codec::MIN_UNITS_PER_VALUE / Codec::MAX_UNITS_PER_VALUE ordering
invariant. Release builds skip this check because the invariant is the
responsibility of the Codec implementation.
Trait Implementations§
Source§impl<C> Debug for CodecValueDecoder<C>
impl<C> Debug for CodecValueDecoder<C>
Source§impl<C> Default for CodecValueDecoder<C>
impl<C> Default for CodecValueDecoder<C>
Source§impl<C> ValueDecoder<[<C as Codec>::Unit]> for CodecValueDecoder<C>
impl<C> ValueDecoder<[<C as Codec>::Unit]> for CodecValueDecoder<C>
Source§fn decode(&mut self, input: &[C::Unit]) -> Result<Self::Output, Self::Error>
fn decode(&mut self, input: &[C::Unit]) -> Result<Self::Output, Self::Error>
Decodes exactly one encoded value from input.
§Parameters
input: Encoded units for exactly one value.
§Returns
Returns the decoded value.
§Errors
Returns CodecDecodeError::Incomplete when fewer than
Codec::MIN_UNITS_PER_VALUE units are available. Returns
CodecDecodeError::Decode when the wrapped codec rejects the input.
Returns CodecDecodeError::TrailingInput when a value is decoded but
extra input remains.
§Panics
Panics when the wrapped codec reports a consumed unit count larger than
the input slice length, or when flush output exceeds
Codec::MAX_DECODE_FLUSH_VALUES.