Skip to main content

DecoderImpl

Struct DecoderImpl 

Source
pub struct DecoderImpl<R, C: Config, Context, const UNTRUSTED: bool = false> { /* private fields */ }
Expand description

A Decoder that reads bytes from a given reader R.

This struct should rarely be used. In most cases, prefer any of the decode functions.

Use Self::new_untrusted to construct a decoder accepted by the explicit untrusted traits. Allocation behavior belongs to the trait being called: Decode retains ordinary behavior even on this decoder; call super::DecodeUntrusted::decode_untrusted for collection safeguards.

The ByteOrder that is chosen will impact the endianness that is used to read integers out of the reader.

use bincode::de::{DecoderImpl, Decode};
let mut context = ();
let mut decoder = DecoderImpl::new(some_reader, bincode::config::standard(), &mut context);
// this u32 can be any Decode
let value = u32::decode(&mut decoder).unwrap();

Implementations§

Source§

impl<R: Reader, C: Config, Context> DecoderImpl<R, C, Context>

Source

pub fn new(reader: R, config: C, context: Context) -> DecoderImpl<R, C, Context>

Construct a new Decoder

Source

pub fn new_untrusted( reader: R, config: C, context: Context, ) -> DecoderImpl<R, C, Context, true>

Construct a decoder accepted by super::DecodeUntrusted.

Call the untrusted traits to use their collection safeguards. The capability is preserved by Decoder::with_context and mutable references.

Trait Implementations§

Source§

impl<'de, R: BorrowReader<'de>, C: Config, Context, const UNTRUSTED: bool> BorrowDecoder<'de> for DecoderImpl<R, C, Context, UNTRUSTED>

Source§

type BR = R

The concrete BorrowReader type
Source§

fn borrow_reader(&mut self) -> &mut Self::BR

Rerturns a mutable reference to the borrow reader
Source§

impl<R: Reader, C: Config, Context, const UNTRUSTED: bool> Decoder for DecoderImpl<R, C, Context, UNTRUSTED>

Source§

type R = R

The concrete Reader type
Source§

type C = C

The concrete Config type
Source§

type Context = Context

The decoding context type
Source§

fn reader(&mut self) -> &mut Self::R

Returns a mutable reference to the reader
Source§

fn config(&self) -> &Self::C

Returns a reference to the config
Source§

fn claim_bytes_read(&mut self, n: usize) -> Result<(), DecodeError>

Claim that n bytes are going to be read from the decoder. This can be used to validate Configuration::Limit<N>().
Source§

fn unclaim_bytes_read(&mut self, n: usize)

Notify the decoder that n bytes are being reclaimed. Read more
Source§

fn context(&mut self) -> &mut Self::Context

Returns the decoding context
Source§

fn with_context<C>(&mut self, context: C) -> WithContext<'_, Self, C>

Wraps decoder with a context
Source§

fn claim_container_read<T>(&mut self, len: usize) -> Result<(), DecodeError>

Claim that we’re going to read a container which contains len entries of T. This will correctly handle overflowing if len * size_of::<T>() > usize::max_value
Source§

impl<R: Reader, C: Config, Context> UntrustedDecoder for DecoderImpl<R, C, Context, true>

Auto Trait Implementations§

§

impl<R, C, Context, const UNTRUSTED: bool> Freeze for DecoderImpl<R, C, Context, UNTRUSTED>
where R: Freeze, C: Freeze, Context: Freeze,

§

impl<R, C, Context, const UNTRUSTED: bool> RefUnwindSafe for DecoderImpl<R, C, Context, UNTRUSTED>
where R: RefUnwindSafe, C: RefUnwindSafe, Context: RefUnwindSafe,

§

impl<R, C, Context, const UNTRUSTED: bool> Send for DecoderImpl<R, C, Context, UNTRUSTED>
where R: Send, C: Send, Context: Send,

§

impl<R, C, Context, const UNTRUSTED: bool> Sync for DecoderImpl<R, C, Context, UNTRUSTED>
where R: Sync, C: Sync, Context: Sync,

§

impl<R, C, Context, const UNTRUSTED: bool> Unpin for DecoderImpl<R, C, Context, UNTRUSTED>
where R: Unpin, C: Unpin, Context: Unpin,

§

impl<R, C, Context, const UNTRUSTED: bool> UnsafeUnpin for DecoderImpl<R, C, Context, UNTRUSTED>
where R: UnsafeUnpin, C: UnsafeUnpin, Context: UnsafeUnpin,

§

impl<R, C, Context, const UNTRUSTED: bool> UnwindSafe for DecoderImpl<R, C, Context, UNTRUSTED>
where R: UnwindSafe, C: UnwindSafe, Context: 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<'de, D> BorrowUntrustedDecoder<'de> for D

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.