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) { ... }
fn append_with<T>(
&mut self,
len: usize,
append: impl FnOnce(&mut Vec<u8>) -> T,
) -> T { ... }
fn append_limit(&self) -> 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§
Provided Methods§
fn write_byte(&mut self, byte: u8)
fn reserve(&mut self, _additional: usize)
Sourcefn write_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8]) -> usize)
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.
Sourcefn append_with<T>(
&mut self,
len: usize,
append: impl FnOnce(&mut Vec<u8>) -> T,
) -> T
fn append_with<T>( &mut self, len: usize, append: impl FnOnce(&mut Vec<u8>) -> T, ) -> T
Hands append a buffer to append at most len bytes to, passes what
it appended on to the sink and returns what append returned.
Sinks backed by a Vec<u8> hand over that vector, so the encoders
write their output in place.
Sourcefn append_limit(&self) -> usize
fn append_limit(&self) -> usize
Largest len worth passing to Writer::append_with at once;
longer output is appended in pieces of at most this size.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".