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<()> { ... }
}
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§
Sourcefn read(&self, offset: usize, writer: &mut VmWriter<'_>) -> Result<()>
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.
Sourcefn write(&self, offset: usize, reader: &mut VmReader<'_>) -> Result<()>
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§
Sourcefn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>
Sourcefn read_val<T: Pod>(&self, offset: usize) -> Result<T>
fn read_val<T: Pod>(&self, offset: usize) -> Result<T>
Reads a value of a specified type at a specified offset.
Sourcefn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>
fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>
Sourcefn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>
fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>
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.