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§
Sourcetype Return
type Return
Optional return type for the Self::finish method.
Required Methods§
Sourcefn capacity(&self) -> usize
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.
Sourcefn skip(&mut self, len: usize) -> Result<(), WriteTooLargeError>
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().