ZByteWriterTrait

Trait ZByteWriterTrait 

Source
pub trait ZByteWriterTrait {
    // Required methods
    fn write_bytes(&mut self, buf: &[u8]) -> Result<usize, ZByteIoError>;
    fn write_all_bytes(&mut self, buf: &[u8]) -> Result<(), ZByteIoError>;
    fn write_const_bytes<const N: usize>(
        &mut self,
        buf: &[u8; N],
    ) -> Result<(), ZByteIoError>;
    fn flush_bytes(&mut self) -> Result<(), ZByteIoError>;
    fn reserve_capacity(&mut self, size: usize) -> Result<(), ZByteIoError>;
}
Expand description

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§

Source

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

Source

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

Source

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)

Source

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 like

After this, the encoder should be able to guarantee that all in-core data is synced with the storage decive

Source

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 Vec can use this to reserve additional memory to prevent reallocation when encoding

This is just a hint, akin to calling Vec::reserve and should be treated as such. If your implementation doesn’t support such, e.g file or mutable slices, it’s okay to return Ok(())

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 ZByteWriterTrait for &mut Vec<u8>

Source§

fn write_bytes(&mut self, buf: &[u8]) -> Result<usize, ZByteIoError>

Source§

fn write_all_bytes(&mut self, buf: &[u8]) -> Result<(), ZByteIoError>

Source§

fn write_const_bytes<const N: usize>( &mut self, buf: &[u8; N], ) -> Result<(), ZByteIoError>

Source§

fn flush_bytes(&mut self) -> Result<(), ZByteIoError>

Source§

fn reserve_capacity(&mut self, size: usize) -> Result<(), ZByteIoError>

Source§

impl ZByteWriterTrait for &mut [u8]

Source§

fn write_bytes(&mut self, buf: &[u8]) -> Result<usize, ZByteIoError>

Source§

fn write_all_bytes(&mut self, buf: &[u8]) -> Result<(), ZByteIoError>

Source§

fn write_const_bytes<const N: usize>( &mut self, buf: &[u8; N], ) -> Result<(), ZByteIoError>

Source§

fn flush_bytes(&mut self) -> Result<(), ZByteIoError>

Source§

fn reserve_capacity(&mut self, _: usize) -> Result<(), ZByteIoError>

Implementors§