Struct wasmer::MemoryView
source · pub struct MemoryView<'a>(pub(crate) 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.view() method.
Tuple Fields§
§0: MemoryView<'a>
Implementations§
source§impl<'a> MemoryView<'a>
impl<'a> MemoryView<'a>
pub(crate) fn new( memory: &Memory, store: &'a (impl AsStoreRef + ?Sized), ) -> Self
pub(crate) fn buffer(&'a self) -> MemoryBuffer<'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_range_to_vec(
&self,
range: Range<u64>,
) -> Result<Vec<u8>, MemoryAccessError>
pub fn copy_range_to_vec( &self, range: Range<u64>, ) -> Result<Vec<u8>, MemoryAccessError>
Copies a range of 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
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for MemoryView<'a>
impl<'a> RefUnwindSafe for MemoryView<'a>
impl<'a> !Send for MemoryView<'a>
impl<'a> !Sync for MemoryView<'a>
impl<'a> Unpin for MemoryView<'a>
impl<'a> UnwindSafe for MemoryView<'a>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more