pub struct CodecValueDecoder<C> { /* 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
Panics when the supplied codec violates the
Codec::min_units_per_value / Codec::max_units_per_value ordering
invariant. Validating once at construction lets the hot decode path
skip the check.
Trait Implementations§
Source§impl<C: Clone> Clone for CodecValueDecoder<C>
impl<C: Clone> Clone for CodecValueDecoder<C>
Source§fn clone(&self) -> CodecValueDecoder<C>
fn clone(&self) -> CodecValueDecoder<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<C: Copy> Copy for CodecValueDecoder<C>
Source§impl<C: Debug> Debug for CodecValueDecoder<C>
impl<C: Debug> Debug for CodecValueDecoder<C>
Source§impl<C: Default> Default for CodecValueDecoder<C>
impl<C: Default> Default for CodecValueDecoder<C>
Source§fn default() -> CodecValueDecoder<C>
fn default() -> CodecValueDecoder<C>
impl<C: Eq> Eq for CodecValueDecoder<C>
Source§impl<C: Hash> Hash for CodecValueDecoder<C>
impl<C: Hash> Hash for CodecValueDecoder<C>
Source§impl<C: PartialEq> PartialEq for CodecValueDecoder<C>
impl<C: PartialEq> PartialEq for CodecValueDecoder<C>
Source§fn eq(&self, other: &CodecValueDecoder<C>) -> bool
fn eq(&self, other: &CodecValueDecoder<C>) -> bool
self and other values to be equal, and is used by ==.impl<C: PartialEq> StructuralPartialEq for CodecValueDecoder<C>
Source§impl<C> ValueDecoder<[<C as Codec>::Unit]> for CodecValueDecoder<C>where
C: Codec,
impl<C> ValueDecoder<[<C as Codec>::Unit]> for CodecValueDecoder<C>where
C: Codec,
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.