Skip to main content

EncoderImpl

Struct 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_next::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 const fn new(writer: W, config: C) -> Self

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>

Source§

type C = C

The concrete Config type
Source§

type W = W

The concrete Writer 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 Read more
Source§

fn encode_u8(&mut self, val: u8) -> Result<(), EncodeError>

Encode a u8 value. Read more
Source§

fn encode_u16(&mut self, val: u16) -> Result<(), EncodeError>

Encode a u16 value. Read more
Source§

fn encode_u32(&mut self, val: u32) -> Result<(), EncodeError>

Encode a u32 value. Read more
Source§

fn encode_u64(&mut self, val: u64) -> Result<(), EncodeError>

Encode a u64 value. Read more
Source§

fn encode_u128(&mut self, val: u128) -> Result<(), EncodeError>

Encode a u128 value. Read more
Source§

fn encode_usize(&mut self, val: usize) -> Result<(), EncodeError>

Encode a usize value. Read more
Source§

fn encode_i8(&mut self, val: i8) -> Result<(), EncodeError>

Encode an i8 value. Read more
Source§

fn encode_i16(&mut self, val: i16) -> Result<(), EncodeError>

Encode an i16 value. Read more
Source§

fn encode_i32(&mut self, val: i32) -> Result<(), EncodeError>

Encode an i32 value. Read more
Source§

fn encode_i64(&mut self, val: i64) -> Result<(), EncodeError>

Encode an i64 value. Read more
Source§

fn encode_i128(&mut self, val: i128) -> Result<(), EncodeError>

Encode an i128 value. Read more
Source§

fn encode_isize(&mut self, val: isize) -> Result<(), EncodeError>

Encode an isize value. Read more
Source§

fn encode_f32(&mut self, val: f32) -> Result<(), EncodeError>

Encode an f32 value. Read more
Source§

fn encode_f64(&mut self, val: f64) -> Result<(), EncodeError>

Encode an f64 value. Read more
Source§

fn encode_bool(&mut self, val: bool) -> Result<(), EncodeError>

Encode a bool value. Read more
Source§

fn encode_str(&mut self, val: &str) -> Result<(), EncodeError>

Encode a string. Read more
Source§

fn encode_slice_len(&mut self, len: usize) -> Result<(), EncodeError>

Encode the length of a slice. Read more
Source§

fn encode_array_len(&mut self, len: usize) -> Result<(), EncodeError>

Encode the length of an array. Read more
Source§

fn encode_map_len(&mut self, len: usize) -> Result<(), EncodeError>

Encode the length of a map. Read more
Source§

fn encode_byte_slice(&mut self, val: &[u8]) -> Result<(), EncodeError>

Encode a byte slice. Read more
Source§

fn encode_struct_header(&mut self, len: usize) -> Result<(), EncodeError>

Encode a struct header. Read more
Source§

fn encode_byte_slice_len(&mut self, len: usize) -> Result<(), EncodeError>

Encode the length of a byte slice. Read more
Source§

fn encode_variant_index(&mut self, idx: u32) -> Result<(), EncodeError>

Encode an enum variant index. Read more

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

§

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

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.