Trait VmIo

Source
pub trait VmIo: Send + Sync {
    // Required methods
    fn read(&self, offset: usize, writer: &mut VmWriter<'_>) -> Result<()>;
    fn write(&self, offset: usize, reader: &mut VmReader<'_>) -> Result<()>;

    // Provided methods
    fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()> { ... }
    fn read_val<T: Pod>(&self, offset: usize) -> Result<T> { ... }
    fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()> { ... }
    fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()> { ... }
    fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()> { ... }
    fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()> { ... }
    fn write_vals<'a, T: Pod + 'a, I: Iterator<Item = &'a T>>(
        &self,
        offset: usize,
        iter: I,
        align: usize,
    ) -> Result<usize> { ... }
}
Expand description

A trait that enables reading/writing data from/to a VM object, e.g., USegment, Vec<UFrame> and UFrame.

§Concurrency

The methods may be executed by multiple concurrent reader and writer threads. In this case, if the results of concurrent reads or writes desire predictability or atomicity, the users should add extra mechanism for such properties.

Required Methods§

Source

fn read(&self, offset: usize, writer: &mut VmWriter<'_>) -> Result<()>

Reads requested data at a specified offset into a given VmWriter.

§No short reads

On success, the writer must be written with the requested data completely. If, for any reason, the requested data is only partially available, then the method shall return an error.

Source

fn write(&self, offset: usize, reader: &mut VmReader<'_>) -> Result<()>

Writes all data from a given VmReader at a specified offset.

§No short writes

On success, the data from the reader must be read to the VM object entirely. If, for any reason, the input data can only be written partially, then the method shall return an error.

Provided Methods§

Source

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

Reads a specified number of bytes at a specified offset into a given buffer.

§No short reads

Similar to read.

Source

fn read_val<T: Pod>(&self, offset: usize) -> Result<T>

Reads a value of a specified type at a specified offset.

Source

fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>

Reads a slice of a specified type at a specified offset.

§No short reads

Similar to read.

Source

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

Writes a specified number of bytes from a given buffer at a specified offset.

§No short writes

Similar to write.

Source

fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()>

Writes a value of a specified type at a specified offset.

Source

fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()>

Writes a slice of a specified type at a specified offset.

§No short write

Similar to write.

Source

fn write_vals<'a, T: Pod + 'a, I: Iterator<Item = &'a T>>( &self, offset: usize, iter: I, align: usize, ) -> Result<usize>

Writes a sequence of values given by an iterator (iter) from the specified offset (offset).

The write process stops until the VM object does not have enough remaining space or the iterator returns None. If any value is written, the function returns Ok(nr_written), where nr_written is the number of the written values.

The offset of every value written by this method is aligned to the align-byte boundary. Naturally, when align equals to 0 or 1, then the argument takes no effect: the values will be written in the most compact way.

§Example

Initializes an VM object with the same value can be done easily with write_values.

use core::iter::self;

let _nr_values = vm_obj.write_vals(0, iter::repeat(0_u32), 0).unwrap();
§Panics

This method panics if align is greater than two, but not a power of two, in release mode.

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<T: VmIo> VmIo for &T

Source§

fn read(&self, offset: usize, writer: &mut VmWriter<'_>) -> Result<()>

Source§

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

Source§

fn read_val<F: Pod>(&self, offset: usize) -> Result<F>

Source§

fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>

Source§

fn write(&self, offset: usize, reader: &mut VmReader<'_>) -> Result<()>

Source§

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

Source§

fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>

Source§

fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>

Source§

impl<T: VmIo> VmIo for &mut T

Source§

fn read(&self, offset: usize, writer: &mut VmWriter<'_>) -> Result<()>

Source§

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

Source§

fn read_val<F: Pod>(&self, offset: usize) -> Result<F>

Source§

fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>

Source§

fn write(&self, offset: usize, reader: &mut VmReader<'_>) -> Result<()>

Source§

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

Source§

fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>

Source§

fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>

Implementors§