Struct bincode::enc::write::SliceWriter

source ·
pub struct SliceWriter<'storage> { /* private fields */ }
Expand description

A helper struct that implements Writer for a &[u8] slice.

use bincode::enc::write::{Writer, SliceWriter};

let destination = &mut [0u8; 100];
let mut writer = SliceWriter::new(destination);
writer.write(&[1, 2, 3, 4, 5]).unwrap();

assert_eq!(writer.bytes_written(), 5);
assert_eq!(destination[0..6], [1, 2, 3, 4, 5, 0]);

Implementations§

source§

impl<'storage> SliceWriter<'storage>

source

pub fn new(bytes: &'storage mut [u8]) -> SliceWriter<'storage>

Create a new instance of SliceWriter with the given byte array.

source

pub fn bytes_written(&self) -> usize

Return the amount of bytes written so far.

Trait Implementations§

source§

impl<'storage> Writer for SliceWriter<'storage>

source§

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

Write bytes to the underlying writer. Exactly bytes.len() bytes must be written, or else an error should be returned.

Auto Trait Implementations§

§

impl<'storage> Freeze for SliceWriter<'storage>

§

impl<'storage> RefUnwindSafe for SliceWriter<'storage>

§

impl<'storage> Send for SliceWriter<'storage>

§

impl<'storage> Sync for SliceWriter<'storage>

§

impl<'storage> Unpin for SliceWriter<'storage>

§

impl<'storage> !UnwindSafe for SliceWriter<'storage>

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.