Struct wasmer::MemoryView
source · pub struct MemoryView<'a>(_);
Expand description
A WebAssembly memory
view.
A memory view is used to read and write to the linear memory.
After a memory is grown a view must not be used anymore. Views are created using the Memory.grow() method.
Implementations§
source§impl<'a> MemoryView<'a>
impl<'a> MemoryView<'a>
sourcepub fn read(&self, offset: u64, buf: &mut [u8]) -> Result<(), MemoryAccessError>
pub fn read(&self, offset: u64, buf: &mut [u8]) -> Result<(), MemoryAccessError>
Safely reads bytes from the memory at the given offset.
The full buffer will be filled, otherwise a MemoryAccessError
is returned
to indicate an out-of-bounds access.
This method is guaranteed to be safe (from the host side) in the face of concurrent writes.
sourcepub fn read_u8(&self, offset: u64) -> Result<u8, MemoryAccessError>
pub fn read_u8(&self, offset: u64) -> Result<u8, MemoryAccessError>
Safely reads a single byte from memory at the given offset
This method is guaranteed to be safe (from the host side) in the face of concurrent writes.
sourcepub fn read_uninit<'b>(
&self,
offset: u64,
buf: &'b mut [MaybeUninit<u8>]
) -> Result<&'b mut [u8], MemoryAccessError>
pub fn read_uninit<'b>( &self, offset: u64, buf: &'b mut [MaybeUninit<u8>] ) -> Result<&'b mut [u8], MemoryAccessError>
Safely reads bytes from the memory at the given offset.
This method is similar to read
but allows reading into an
uninitialized buffer. An initialized view of the buffer is returned.
The full buffer will be filled, otherwise a MemoryAccessError
is returned
to indicate an out-of-bounds access.
This method is guaranteed to be safe (from the host side) in the face of concurrent writes.
sourcepub fn write(&self, offset: u64, data: &[u8]) -> Result<(), MemoryAccessError>
pub fn write(&self, offset: u64, data: &[u8]) -> Result<(), MemoryAccessError>
Safely writes bytes to the memory at the given offset.
If the write exceeds the bounds of the memory then a MemoryAccessError
is
returned.
This method is guaranteed to be safe (from the host side) in the face of concurrent reads/writes.
sourcepub fn write_u8(&self, offset: u64, val: u8) -> Result<(), MemoryAccessError>
pub fn write_u8(&self, offset: u64, val: u8) -> Result<(), MemoryAccessError>
Safely writes a single byte from memory at the given offset
This method is guaranteed to be safe (from the host side) in the face of concurrent writes.
sourcepub fn copy_to_vec(&self) -> Result<Vec<u8>, MemoryAccessError>
pub fn copy_to_vec(&self) -> Result<Vec<u8>, MemoryAccessError>
Copies the memory and returns it as a vector of bytes
sourcepub fn copy_to_memory(
&self,
amount: u64,
new_memory: &Self
) -> Result<(), MemoryAccessError>
pub fn copy_to_memory( &self, amount: u64, new_memory: &Self ) -> Result<(), MemoryAccessError>
Copies the memory to another new memory object