pub trait ByteWriter {
    fn write_at(
        &mut self,
        buffer: &[u8],
        offset: usize
    ) -> Result<usize, IoError>;
fn flush(&mut self) -> Result<(), IoError>; }
Expand description

A trait that represents an I/O stream that can be written to, but which does not track the current offset into the stream.

ByteWriter implementation atop BlockWriter

The ByteWriter trait ideally should be auto-implemented for any type that implements both the BlockWriter and BlockReader traits to allow easy byte-wise access to a block-based I/O stream. However, Rust does not allow trait specialization yet, so we cannot do this; instead, use the ByteWriterWrapper type to accomplish this.

It is only possible to implement a byte-wise writer atop a block-wise writer AND reader together, because it is often necessary to read an original block of data from the underlying stream before writing a partial block back to the device. This is required to avoid incorrectly overwriting unrelated byte ranges.

Note that other implementations of ByteWriter may not have this restriction, e.g., when the underlying writer supports writing individual bytes.

Required methods

Writes bytes of data from the given buffer to this writer.

The number of bytes written is dictated by the length of the given buffer.

  • buffer: the buffer from which data will be copied.
  • offset: the offset in number of bytes from the beginning of this writer where the write operation will begin.

If successful, returns the number of bytes written to this writer. Otherwise, returns an error.

Flushes this writer’s output stream, ensuring all contents in intermediate buffers are fully written out.

Implementations on Foreign Types