Skip to main content

CodecValueDecoder

Struct CodecValueDecoder 

Source
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,

Source

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>
where C: Codec + Debug,

Source§

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

Formats the decoder without requiring flushed values to be printable.

Source§

impl<C> Default for CodecValueDecoder<C>
where C: Codec + Default,

Source§

fn default() -> Self

Creates a decoder from the default codec.

Source§

impl<C> ValueDecoder<[<C as Codec>::Unit]> for CodecValueDecoder<C>
where C: Codec, C::Value: Default,

Source§

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.

Source§

type Output = <C as Codec>::Value

Decoded output type.
Source§

type Error = TranscodeError<CodecDecodeError<<C as Codec>::DecodeError>>

Decoding error type.

Auto Trait Implementations§

§

impl<C> Freeze for CodecValueDecoder<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for CodecValueDecoder<C>

§

impl<C> Send for CodecValueDecoder<C>
where C: Send, <C as Codec>::Value: Send,

§

impl<C> Sync for CodecValueDecoder<C>
where C: Sync, <C as Codec>::Value: Sync,

§

impl<C> Unpin for CodecValueDecoder<C>
where C: Unpin, <C as Codec>::Value: Unpin,

§

impl<C> UnsafeUnpin for CodecValueDecoder<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for CodecValueDecoder<C>
where C: UnwindSafe, <C as Codec>::Value: UnwindSafe,

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