Writer

Trait Writer 

Source
pub trait Writer {
    type Ok;
    type Mut<'this>: Writer
       where Self: 'this;

    // Required methods
    fn finish<C>(&mut self, cx: C) -> Result<Self::Ok, C::Error>
       where C: Context;
    fn borrow_mut(&mut self) -> Self::Mut<'_>;
    fn extend<C>(
        &mut self,
        cx: C,
        buffer: Vec<u8, C::Allocator>,
    ) -> Result<(), C::Error>
       where C: Context;
    fn write_bytes<C>(&mut self, cx: C, bytes: &[u8]) -> Result<(), C::Error>
       where C: Context;

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

The trait governing how a writer works.

Required Associated Types§

Source

type Ok

The value returned from writing the value.

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 finish<C>(&mut self, cx: C) -> Result<Self::Ok, C::Error>
where C: Context,

Finalize the writer and return the output.

Source

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

Reborrow the current type.

Source

fn extend<C>( &mut self, cx: C, buffer: Vec<u8, C::Allocator>, ) -> Result<(), C::Error>
where C: Context,

Write a buffer to the current writer.

Source

fn write_bytes<C>(&mut self, cx: C, bytes: &[u8]) -> Result<(), C::Error>
where C: 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: Context,

Write a single byte.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Writer for Vec<u8>

Available on crate feature alloc only.
Source§

type Ok = ()

Source§

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

Source§

fn finish<C>(&mut self, _: C) -> Result<Self::Ok, C::Error>
where C: Context,

Source§

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

Source§

fn extend<C>( &mut self, cx: C, buffer: Vec<u8, C::Allocator>, ) -> Result<(), C::Error>
where C: Context,

Source§

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

Source§

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

Source§

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

Source§

type Ok = <W as Writer>::Ok

Source§

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

Source§

fn finish<C>(&mut self, cx: C) -> Result<Self::Ok, C::Error>
where C: Context,

Source§

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

Source§

fn extend<C>( &mut self, cx: C, buffer: Vec<u8, C::Allocator>, ) -> Result<(), C::Error>
where C: Context,

Source§

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

Source§

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

Implementors§

Source§

impl<'a> Writer for SliceMutWriter<'a>

Source§

type Ok = usize

Source§

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

Source§

impl<A> Writer for BufWriter<A>
where A: Allocator,

Source§

type Ok = ()

Source§

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

Source§

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

Available on crate feature std only.
Source§

type Ok = ()

Source§

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

Source§

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

Source§

type Ok = ()

Source§

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