pub struct Memory<'runtime, Instance>where
Instance: CabiReallocAlias + CabiFreeAlias,{ /* private fields */ }
Expand description
A handle to interface with a guest Wasm module instance’s memory.
Implementations§
Source§impl<Instance> Memory<'_, Instance>where
Instance: CabiReallocAlias + CabiFreeAlias,
<Instance::Runtime as Runtime>::Memory: RuntimeMemory<Instance>,
impl<Instance> Memory<'_, Instance>where
Instance: CabiReallocAlias + CabiFreeAlias,
<Instance::Runtime as Runtime>::Memory: RuntimeMemory<Instance>,
Sourcepub fn read(
&self,
location: GuestPointer,
length: u32,
) -> Result<Cow<'_, [u8]>, RuntimeError>
pub fn read( &self, location: GuestPointer, length: u32, ) -> Result<Cow<'_, [u8]>, RuntimeError>
Reads length
bytes from location
.
The underlying runtime may return either a memory slice or an owned buffer.
Sourcepub fn write(
&mut self,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
pub fn write( &mut self, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes bytes
to location
.
Sourcepub fn allocate(
&mut self,
size: u32,
alignment: u32,
) -> Result<GuestPointer, RuntimeError>
pub fn allocate( &mut self, size: u32, alignment: u32, ) -> Result<GuestPointer, RuntimeError>
Returns a newly allocated buffer of size
bytes in the guest module’s memory
aligned to the requested alignment
.
Calls the guest module to allocate the memory, so the resulting allocation is managed by the guest.
Sourcepub fn deallocate(
&mut self,
allocation: GuestPointer,
) -> Result<(), RuntimeError>
pub fn deallocate( &mut self, allocation: GuestPointer, ) -> Result<(), RuntimeError>
Deallocates the allocation
managed by the guest.
Auto Trait Implementations§
impl<'runtime, Instance> Freeze for Memory<'runtime, Instance>
impl<'runtime, Instance> RefUnwindSafe for Memory<'runtime, Instance>where
<<Instance as Instance>::Runtime as Runtime>::Memory: RefUnwindSafe,
Instance: RefUnwindSafe,
<Instance as InstanceWithFunction<HCons<i32, HCons<i32, HCons<i32, HCons<i32, HNil>>>>, HCons<i32, HNil>>>::Function: RefUnwindSafe,
<Instance as InstanceWithFunction<HCons<i32, HNil>, HNil>>::Function: RefUnwindSafe,
impl<'runtime, Instance> Send for Memory<'runtime, Instance>
impl<'runtime, Instance> Sync for Memory<'runtime, Instance>
impl<'runtime, Instance> Unpin for Memory<'runtime, Instance>
impl<'runtime, Instance> !UnwindSafe for Memory<'runtime, Instance>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
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>
Converts
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>
Converts
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 moreSource§impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
Source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads length
bytes from memory from the provided location
.
Source§fn write(
&mut self,
instance: &mut &mut I,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes
to memory at the provided location
.