Skip to main content

Writer

Trait Writer 

Source
pub trait Writer {
    // Required method
    fn write(&mut self, bytes: &[u8]);

    // Provided methods
    fn write_byte(&mut self, byte: u8) { ... }
    fn reserve(&mut self, _additional: usize) { ... }
    fn write_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8]) -> usize) { ... }
}
Expand description

Byte sink used by every serializer in this crate.

Vec<u8> is the primary implementation; IoWriter adapts any std::io::Write with an internal buffer.

Required Methods§

Source

fn write(&mut self, bytes: &[u8])

Provided Methods§

Source

fn write_byte(&mut self, byte: u8)

Source

fn reserve(&mut self, _additional: usize)

Source

fn write_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8]) -> usize)

Hands the sink a scratch region of len bytes, keeps the first fill(region) bytes of it and discards the rest.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Writer for Vec<u8>

Source§

fn write(&mut self, bytes: &[u8])

Source§

fn write_byte(&mut self, byte: u8)

Source§

fn reserve(&mut self, additional: usize)

Source§

fn write_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8]) -> usize)

Source§

impl<W: Writer + ?Sized> Writer for &mut W

Source§

fn write(&mut self, bytes: &[u8])

Source§

fn write_byte(&mut self, byte: u8)

Source§

fn reserve(&mut self, additional: usize)

Source§

fn write_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8]) -> usize)

Implementors§

Source§

impl<W: Write> Writer for IoWriter<W>