Skip to main content

WriteAdapter

Struct WriteAdapter 

Source
pub struct WriteAdapter<W: ?Sized>(/* private fields */);
Expand description

Writer adapter over any std::io::Write sink.

Wraps any W: std::io::Write and exposes it as a wincode Writer, allowing serialization into files, network streams, or other I/O sinks.

§Examples

Serialize a tuple into a Vec<u8> via WriteAdapter:

use wincode::{Serialize, io::{Writer, std_write::WriteAdapter}};

let tuple = (42u32, true, 1234567890i64);
let mut buf = Vec::new();
let mut writer = WriteAdapter::new(&mut buf);
<(u32, bool, i64)>::serialize_into(&mut writer, &tuple).unwrap();
writer.finish().unwrap();
assert_eq!(buf, wincode::serialize(&tuple).unwrap());

Implementations§

Source§

impl<W: Write> WriteAdapter<W>

Source

pub fn new(writer: W) -> Self

Trait Implementations§

Source§

impl<W: Debug + ?Sized> Debug for WriteAdapter<W>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<W: Write + ?Sized> Writer for WriteAdapter<W>

Source§

fn write(&mut self, src: &[u8]) -> WriteResult<()>

Write exactly src.len() bytes from the given src into the writer.
Source§

fn finish(&mut self) -> WriteResult<()>

Finalize the writer by performing any required cleanup or flushing. Read more
Source§

fn by_ref(&mut self) -> impl Writer

Get a mutable reference to the Writer. Read more
Source§

unsafe fn as_trusted_for(&mut self, n_bytes: usize) -> WriteResult<impl Writer>

Advance the parent by n_bytes and return a Writer that can elide bounds checks within that n_bytes window. Read more
Source§

unsafe fn write_t<T: ?Sized>(&mut self, src: &T) -> WriteResult<()>

Write T as bytes into the source. Read more
Source§

unsafe fn write_slice_t<T>(&mut self, src: &[T]) -> WriteResult<()>

Write [T] as bytes into the source. Read more

Auto Trait Implementations§

§

impl<W> Freeze for WriteAdapter<W>
where W: Freeze + ?Sized,

§

impl<W> RefUnwindSafe for WriteAdapter<W>
where W: RefUnwindSafe + ?Sized,

§

impl<W> Send for WriteAdapter<W>
where W: Send + ?Sized,

§

impl<W> Sync for WriteAdapter<W>
where W: Sync + ?Sized,

§

impl<W> Unpin for WriteAdapter<W>
where W: Unpin + ?Sized,

§

impl<W> UnsafeUnpin for WriteAdapter<W>
where W: UnsafeUnpin + ?Sized,

§

impl<W> UnwindSafe for WriteAdapter<W>
where W: UnwindSafe + ?Sized,

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

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.