Trait musli_utils::writer::Writer

source ·
pub trait Writer {
    type Mut<'this>: Writer
       where Self: 'this;

    // Required methods
    fn borrow_mut(&mut self) -> Self::Mut<'_>;
    fn write_buffer<C, B>(&mut self, cx: &C, buffer: B) -> Result<(), C::Error>
       where C: ?Sized + Context,
             B: Buf;
    fn write_bytes<C>(&mut self, cx: &C, bytes: &[u8]) -> Result<(), C::Error>
       where C: ?Sized + Context;

    // Provided method
    fn write_byte<C>(&mut self, cx: &C, b: u8) -> Result<(), C::Error>
       where C: ?Sized + Context { ... }
}
Expand description

The trait governing how a writer works.

Required Associated Types§

source

type Mut<'this>: Writer where Self: 'this

Reborrowed type.

Why oh why would we want to do this over having a simple &'this mut T?

We want to avoid recursive types, which will blow up the compiler. And the above is a typical example of when that can go wrong. This ensures that each call to borrow_mut dereferences the Reader at each step to avoid constructing a large muted type, like &mut &mut &mut VecWriter.

Required Methods§

source

fn borrow_mut(&mut self) -> Self::Mut<'_>

Reborrow the current type.

source

fn write_buffer<C, B>(&mut self, cx: &C, buffer: B) -> Result<(), C::Error>
where C: ?Sized + Context, B: Buf,

Write a buffer to the current writer.

source

fn write_bytes<C>(&mut self, cx: &C, bytes: &[u8]) -> Result<(), C::Error>
where C: ?Sized + Context,

Write bytes to the current writer.

Provided Methods§

source

fn write_byte<C>(&mut self, cx: &C, b: u8) -> Result<(), C::Error>
where C: ?Sized + Context,

Write a single byte.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Writer for &mut [u8]

§

type Mut<'this> = &'this mut &mut [u8] where Self: 'this

source§

fn borrow_mut(&mut self) -> Self::Mut<'_>

source§

fn write_buffer<C, B>(&mut self, cx: &C, buffer: B) -> Result<(), C::Error>
where C: ?Sized + Context, B: Buf,

source§

fn write_bytes<C>(&mut self, cx: &C, bytes: &[u8]) -> Result<(), C::Error>
where C: ?Sized + Context,

source§

fn write_byte<C>(&mut self, cx: &C, b: u8) -> Result<(), C::Error>
where C: ?Sized + Context,

source§

impl Writer for Vec<u8>

§

type Mut<'this> = &'this mut Vec<u8> where Self: 'this

source§

fn borrow_mut(&mut self) -> Self::Mut<'_>

source§

fn write_buffer<C, B>(&mut self, cx: &C, buffer: B) -> Result<(), C::Error>
where C: ?Sized + Context, B: Buf,

source§

fn write_bytes<C>(&mut self, cx: &C, bytes: &[u8]) -> Result<(), C::Error>
where C: ?Sized + Context,

source§

fn write_byte<C>(&mut self, cx: &C, b: u8) -> Result<(), C::Error>
where C: ?Sized + Context,

source§

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

§

type Mut<'this> = &'this mut W where Self: 'this

source§

fn borrow_mut(&mut self) -> Self::Mut<'_>

source§

fn write_buffer<C, B>(&mut self, cx: &C, buffer: B) -> Result<(), C::Error>
where C: ?Sized + Context, B: Buf,

source§

fn write_bytes<C>(&mut self, cx: &C, bytes: &[u8]) -> Result<(), C::Error>
where C: ?Sized + Context,

source§

fn write_byte<C>(&mut self, cx: &C, b: u8) -> Result<(), C::Error>
where C: ?Sized + Context,

Implementors§

source§

impl<T> Writer for BufWriter<T>
where T: Buf,

§

type Mut<'this> = &'this mut BufWriter<T> where Self: 'this

source§

impl<W> Writer for Wrap<W>
where W: Write,

§

type Mut<'this> = &'this mut Wrap<W> where Self: 'this

source§

impl<const N: usize> Writer for FixedBytes<N>

§

type Mut<'this> = &'this mut FixedBytes<N> where Self: 'this