pub struct WasmMemory { /* private fields */ }Expand description
WASM memory abstraction
Implementations§
Source§impl WasmMemory
impl WasmMemory
pub fn new(initial_pages: u32, max_pages: Option<u32>) -> WasmMemory
Sourcepub fn read_mut(
&mut self,
ptr: GuestPtr,
len: u32,
) -> Result<&mut [u8], WasmError>
pub fn read_mut( &mut self, ptr: GuestPtr, len: u32, ) -> Result<&mut [u8], WasmError>
Read bytes as mutable
Sourcepub fn write(&mut self, ptr: GuestPtr, data: &[u8]) -> Result<(), WasmError>
pub fn write(&mut self, ptr: GuestPtr, data: &[u8]) -> Result<(), WasmError>
Write bytes to memory
Sourcepub fn read_string(&self, ptr: GuestPtr, len: u32) -> Result<String, WasmError>
pub fn read_string(&self, ptr: GuestPtr, len: u32) -> Result<String, WasmError>
Read a string from memory (null-terminated or with length)
Sourcepub fn write_string(&mut self, ptr: GuestPtr, s: &str) -> Result<(), WasmError>
pub fn write_string(&mut self, ptr: GuestPtr, s: &str) -> Result<(), WasmError>
Write a string to memory
Sourcepub fn read_value<T>(&self, ptr: GuestPtr) -> Result<T, WasmError>where
T: Copy,
pub fn read_value<T>(&self, ptr: GuestPtr) -> Result<T, WasmError>where
T: Copy,
Read a value of type T
Sourcepub fn write_value<T>(
&mut self,
ptr: GuestPtr,
value: T,
) -> Result<(), WasmError>where
T: Copy,
pub fn write_value<T>(
&mut self,
ptr: GuestPtr,
value: T,
) -> Result<(), WasmError>where
T: Copy,
Write a value of type T
Sourcepub fn alloc(&mut self, size: u32) -> Result<GuestPtr, WasmError>
pub fn alloc(&mut self, size: u32) -> Result<GuestPtr, WasmError>
Allocate memory from the heap
Sourcepub fn free(&mut self, ptr: GuestPtr) -> Result<(), WasmError>
pub fn free(&mut self, ptr: GuestPtr) -> Result<(), WasmError>
Free allocated memory (basic implementation - doesn’t reuse space)
Sourcepub fn alloc_bytes(&mut self, data: &[u8]) -> Result<GuestSlice, WasmError>
pub fn alloc_bytes(&mut self, data: &[u8]) -> Result<GuestSlice, WasmError>
Allocate and write data
Sourcepub fn alloc_string(&mut self, s: &str) -> Result<GuestSlice, WasmError>
pub fn alloc_string(&mut self, s: &str) -> Result<GuestSlice, WasmError>
Allocate and write string
Trait Implementations§
Source§impl Default for WasmMemory
impl Default for WasmMemory
Source§fn default() -> WasmMemory
fn default() -> WasmMemory
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for WasmMemory
impl RefUnwindSafe for WasmMemory
impl Send for WasmMemory
impl Sync for WasmMemory
impl Unpin for WasmMemory
impl UnsafeUnpin for WasmMemory
impl UnwindSafe for WasmMemory
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<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>
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<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage