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§
Sourcetype Mut<'this>: Writer
where
Self: 'this
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§
Sourcefn finish<C>(&mut self, cx: C) -> Result<Self::Ok, C::Error>where
C: Context,
fn finish<C>(&mut self, cx: C) -> Result<Self::Ok, C::Error>where
C: Context,
Finalize the writer and return the output.
Sourcefn borrow_mut(&mut self) -> Self::Mut<'_>
fn borrow_mut(&mut self) -> Self::Mut<'_>
Reborrow the current type.
Provided Methods§
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.
impl Writer for Vec<u8>
Available on crate feature
alloc only.