Struct bincode::enc::EncoderImpl

source ·
pub struct EncoderImpl<W: Writer, C: Config> { /* private fields */ }
Expand description

An Encoder that writes bytes into a given writer W.

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

The ByteOrder that is chosen will impact the endianness that is used to write integers to the writer.

let slice: &mut [u8] = &mut [0, 0, 0, 0];
let config = bincode::config::legacy().with_big_endian();

let mut encoder = EncoderImpl::new(SliceWriter::new(slice), config);
// this u32 can be any Encodable
5u32.encode(&mut encoder).unwrap();
assert_eq!(encoder.into_writer().bytes_written(), 4);
assert_eq!(slice, [0, 0, 0, 5]);

Implementations§

source§

impl<W: Writer, C: Config> EncoderImpl<W, C>

source

pub fn new(writer: W, config: C) -> EncoderImpl<W, C>

Create a new Encoder

source

pub fn into_writer(self) -> W

Return the underlying writer

Trait Implementations§

source§

impl<W: Writer, C: Config> Encoder for EncoderImpl<W, C>

§

type W = W

The concrete Writer type
§

type C = C

The concrete Config type
source§

fn writer(&mut self) -> &mut Self::W

Returns a mutable reference to the writer
source§

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

Returns a reference to the config

Auto Trait Implementations§

§

impl<W, C> Freeze for EncoderImpl<W, C>
where W: Freeze, C: Freeze,

§

impl<W, C> RefUnwindSafe for EncoderImpl<W, C>

§

impl<W, C> Send for EncoderImpl<W, C>
where W: Send, C: Send,

§

impl<W, C> Sync for EncoderImpl<W, C>
where W: Sync, C: Sync,

§

impl<W, C> Unpin for EncoderImpl<W, C>
where W: Unpin, C: Unpin,

§

impl<W, C> UnwindSafe for EncoderImpl<W, C>
where W: UnwindSafe, C: 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>,

§

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

§

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.