Trait io::ByteWriter

source ·
pub trait ByteWriter {
    // Required methods
    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§

source

fn write_at(&mut self, buffer: &[u8], offset: usize) -> Result<usize, IoError>

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.

Arguments
  • 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.
Return

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

source

fn flush(&mut self) -> Result<(), IoError>

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

Implementations on Foreign Types§

source§

impl<R> ByteWriter for &mut Rwhere R: ByteWriter + ?Sized,

source§

fn write_at( &mut self, buffer: &[u8], block_offset: usize ) -> Result<usize, IoError>

source§

fn flush(&mut self) -> Result<(), IoError>

source§

impl<R> ByteWriter for Box<R>where R: ByteWriter + ?Sized,

source§

fn write_at(&mut self, buffer: &[u8], offset: usize) -> Result<usize, IoError>

source§

fn flush(&mut self) -> Result<(), IoError>

Implementors§

source§

impl<'io, IO, L, B> ByteWriter for &LockableIo<'io, IO, L, B>where IO: ByteWriter + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

impl<'io, IO, L, B> ByteWriter for LockableIo<'io, IO, L, B>where IO: ByteWriter + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

impl<IO> ByteWriter for ReaderWriter<IO>where IO: ByteWriter,

source§

impl<IO> ByteWriter for Writer<IO>where IO: ByteWriter,

source§

impl<RW> ByteWriter for ByteReaderWriterWrapper<RW>where RW: BlockReader + BlockWriter,

source§

impl<RW> ByteWriter for ByteWriterWrapper<RW>where RW: BlockReader + BlockWriter,