Trait ZByteWriterTrait
pub trait ZByteWriterTrait
The writer trait implemented for zune-image library of encoders
Anything that implements this trait can be used as a sink for writing encoded images
Required Methods
fn write_bytes(&mut self, buf: &[u8]) -> Result<usize, ZByteIoError>Write some bytes into the sink returning number of bytes written or an error if something bad happened
An implementation is free to write less bytes that are in buf, so the bytes written cannot be guaranteed to be fully written
fn write_all_bytes(&mut self, buf: &[u8]) -> Result<(), ZByteIoError>Write all bytes to the buffer or return an error if something occurred
This will always write all bytes, if it can't fully write all bytes, it will error out
fn write_const_bytes<const N: usize>(&mut self, buf: &[u8; N]) -> Result<(), ZByteIoError>Write a fixed number of bytes and error out if we can't write the bytes
This is provided to allow for optimized writes where possible. (when the compiler can const fold them)
fn flush_bytes(&mut self) -> Result<(), ZByteIoError>Ensure bytes are written to the sink.
Implementations should treat this like linux
fsync, and should implement whatever writer's implementation of fsync should look likeAfter this, the encoder should be able to guarantee that all in-core data is synced with the storage decive
fn reserve_capacity(&mut self, size: usize) -> Result<(), ZByteIoError>A hint to tell the implementation how big of a size we expect the image to be An implementation like in memory
Veccan use this to reserve additional memory to prevent reallocation when encodingThis is just a hint, akin to calling
Vec::reserveand should be treated as such. If your implementation doesn't support such, e.g file or mutable slices, it's okay to returnOk(())
Implementors
impl<T: Write> ZByteWriterTrait for T