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>) -> Self
Sourcepub fn grow(&mut self, delta: u32) -> WasmResult<u32>
pub fn grow(&mut self, delta: u32) -> WasmResult<u32>
Grow memory by delta pages
Sourcepub fn read_mut(&mut self, ptr: GuestPtr, len: u32) -> WasmResult<&mut [u8]>
pub fn read_mut(&mut self, ptr: GuestPtr, len: u32) -> WasmResult<&mut [u8]>
Read bytes as mutable
Sourcepub fn read_string(&self, ptr: GuestPtr, len: u32) -> WasmResult<String>
pub fn read_string(&self, ptr: GuestPtr, len: u32) -> WasmResult<String>
Read a string from memory (null-terminated or with length)
Sourcepub fn write_string(&mut self, ptr: GuestPtr, s: &str) -> WasmResult<()>
pub fn write_string(&mut self, ptr: GuestPtr, s: &str) -> WasmResult<()>
Write a string to memory
Sourcepub fn read_value<T: Copy>(&self, ptr: GuestPtr) -> WasmResult<T>
pub fn read_value<T: Copy>(&self, ptr: GuestPtr) -> WasmResult<T>
Read a value of type T
Sourcepub fn write_value<T: Copy>(
&mut self,
ptr: GuestPtr,
value: T,
) -> WasmResult<()>
pub fn write_value<T: Copy>( &mut self, ptr: GuestPtr, value: T, ) -> WasmResult<()>
Write a value of type T
Sourcepub fn alloc(&mut self, size: u32) -> WasmResult<GuestPtr>
pub fn alloc(&mut self, size: u32) -> WasmResult<GuestPtr>
Allocate memory from the heap
Sourcepub fn free(&mut self, ptr: GuestPtr) -> WasmResult<()>
pub fn free(&mut self, ptr: GuestPtr) -> WasmResult<()>
Free allocated memory (basic implementation - doesn’t reuse space)
Sourcepub fn alloc_bytes(&mut self, data: &[u8]) -> WasmResult<GuestSlice>
pub fn alloc_bytes(&mut self, data: &[u8]) -> WasmResult<GuestSlice>
Allocate and write data
Sourcepub fn alloc_string(&mut self, s: &str) -> WasmResult<GuestSlice>
pub fn alloc_string(&mut self, s: &str) -> WasmResult<GuestSlice>
Allocate and write string
Trait Implementations§
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 more