Writer

Trait Writer 

Source
pub trait Writer {
    type Return;

    // Required methods
    fn capacity(&self) -> usize;
    fn skip(&mut self, len: usize) -> Result<(), WriteTooLargeError>;
    fn write_bytes(&mut self, data: &[u8]) -> Result<(), WriteTooLargeError>;
    fn finish(self) -> Self::Return;
}
Expand description

An object to which bytes can be written.

Writes may be buffered, so it is required to call Self::finish to flush pending writes. Using a Writer and dropping it afterwards instead of calling Self::finish on it is a logic error.

Required Associated Types§

Source

type Return

Optional return type for the Self::finish method.

Required Methods§

Source

fn capacity(&self) -> usize

Return the number of bytes that can still be written to self.

When the writer has infinite capacity then usize::MAX is returned.

Source

fn skip(&mut self, len: usize) -> Result<(), WriteTooLargeError>

Skip over len bytes. If skipping over bytes is not meaningful for the buffer then this is a no-op.

§Errors

Errors when len > self.capacity().

Source

fn write_bytes(&mut self, data: &[u8]) -> Result<(), WriteTooLargeError>

Write data.len() bytes to the buffer.

§Errors

Errors when data.len() > self.capacity().

Source

fn finish(self) -> Self::Return

Flush any pending/buffered writes and optionally return something.

If the buffer must initialise leftover bytes it will set them to zero.

Implementors§

Source§

impl<'a> Writer for BufMut<'a>