pub struct MemoryView<'a>(/* private fields */);
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.
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_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§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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