pub struct ByteReaderWriterWrapper<RW: BlockReader + BlockWriter>(/* private fields */);
Expand description

A wrapper struct that implements a byte-wise reader and writer atop a block-based reader and writer.

This ideally should be realized via automatic trait implementations, in which all types that implement BlockReader + BlockWriter also implement ByteReader + ByteWriter, but we cannot do that because Rust currently does not support specialization.

Example

Use the From implementation around a BlockReader + BlockWriter instance, such as:

// Assume `storage_dev` implements `BlockReader + BlockWriter`
let mut reader_writer = ByteReaderWriterWrapper::from(storage_dev); 
let bytes_read = reader_writer.read_at(...);
let bytes_written = reader_writer.write_at(...);

Trait Implementations§

source§

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

source§

fn block_size(&self) -> usize

Returns the size in bytes of a single block (i.e., sector), the minimum granularity of I/O transfers.
source§

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

source§

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

Reads blocks of data from this reader into the given buffer. Read more
source§

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

source§

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

Writes blocks of data from the given buffer to this writer. Read more
source§

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

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

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

source§

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

Reads bytes of data from this reader into the given buffer. Read more
source§

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

source§

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

Writes bytes of data from the given buffer to this writer. Read more
source§

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

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

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

source§

fn from(block_reader_writer: RW) -> Self

Converts to this type from the input type.
source§

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

source§

fn len(&self) -> usize

Returns the length (size in bytes) of this I/O stream or device.

Auto Trait Implementations§

§

impl<RW> RefUnwindSafe for ByteReaderWriterWrapper<RW>where RW: RefUnwindSafe,

§

impl<RW> Send for ByteReaderWriterWrapper<RW>where RW: Send,

§

impl<RW> Sync for ByteReaderWriterWrapper<RW>where RW: Sync,

§

impl<RW> Unpin for ByteReaderWriterWrapper<RW>where RW: Unpin,

§

impl<RW> UnwindSafe for ByteReaderWriterWrapper<RW>where RW: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.