Struct wasmedge_sys::Memory

source ·
pub struct Memory { /* private fields */ }
Expand description

Defines a WebAssembly memory instance, which is a linear memory described by its type. Each memory instance consists of a vector of bytes and an optional maximum size, and its size is a multiple of the WebAssembly page size (64KiB of each page).

Implementations§

source§

impl Memory

source

pub fn create(ty: &MemoryType) -> WasmEdgeResult<Self>

Create a new Memory to be associated with the given capacity limit.

§Arguments
  • ty - The type of the new Memory instance.
§Errors
source

pub fn ty(&self) -> WasmEdgeResult<MemoryType>

Returns the type of the Memory.

§Errors

If fail to get the type from the Memory, then an error is returned.

source

pub fn get_data(&self, offset: u32, len: u32) -> WasmEdgeResult<Vec<u8>>

Copies the data from the Memory to the output buffer.

§Arguments
  • offset - The data start offset in the Memory.

  • len - The requested data length.

§Errors

If the offset + len is larger than the data size in the Memory, then an error is returned.

source

pub fn set_data( &mut self, data: impl AsRef<[u8]>, offset: u32 ) -> WasmEdgeResult<()>

Copies the data from the given input buffer into the Memory.

§Arguments
  • data - The data buffer to copy.

  • offset - The data start offset in the Memory.

§Errors

If the sum of the offset and the data length is larger than the size of the Memory, then an error is returned.

source

pub unsafe fn data_pointer( &self, offset: u32, len: u32 ) -> WasmEdgeResult<*const u8>

Returns the const data pointer to the Memory.

§Arguments
  • offset - The data start offset in the Memory.

  • len - The requested data length. If the size of offset + len is larger than the data size in the Memory

§Errors

If fail to get the data pointer, then an error is returned.

§Safety

The lifetime of the returned pointer must not exceed that of the object itself.

source

pub unsafe fn data_pointer_mut( &mut self, offset: u32, len: u32 ) -> WasmEdgeResult<*mut u8>

Returns the data pointer to the Memory.

§Arguments
  • offset - The data start offset in the Memory.

  • len - The requested data length. If the size of offset + len is larger than the data size in the Memory

§Errors

If fail to get the data pointer, then an error is returned.

§Safety

The lifetime of the returned pointer must not exceed that of the object itself.

source

pub fn size(&self) -> u32

Returns the size, in WebAssembly pages (64 KiB of each page), of this wasm memory.

source

pub fn grow(&mut self, count: u32) -> WasmEdgeResult<()>

Grows this WebAssembly memory by count pages.

§Arguments
  • count - The page counts to be extended to the Memory.
§Errors

If fail to grow the page count, then an error is returned.

source

pub unsafe fn as_ptr(&self) -> *const WasmEdge_MemoryInstanceContext

§Safety

Provides a raw pointer to the inner memory context. The lifetime of the returned pointer must not exceed that of the object itself.

source§

impl Memory

source

pub fn get_ref<T: Sized>(&self, offset: usize) -> Option<&T>

source

pub fn slice<T: Sized>(&self, offset: usize, len: usize) -> Option<&[T]>

source

pub fn get_ref_mut<T: Sized>(&mut self, offset: usize) -> Option<&mut T>

source

pub fn mut_slice<T: Sized>(&self, offset: usize, len: usize) -> Option<&mut [T]>

source

pub fn write<T: Sized>(&mut self, offset: usize, data: T) -> Option<()>

Trait Implementations§

source§

impl Debug for Memory

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Memory

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Memory for Memory

Available on crate feature async and Linux only.
source§

fn get_data<T: Sized>(&self, offset: WasmPtr<T>) -> Result<&T, Errno>

source§

fn get_slice<T: Sized>( &self, offset: WasmPtr<T>, len: usize ) -> Result<&[T], Errno>

source§

fn get_iovec<'a>( &self, iovec_ptr: WasmPtr<__wasi_ciovec_t>, iovec_len: __wasi_size_t ) -> Result<Vec<IoSlice<'a>>, Errno>

source§

fn mut_data<T: Sized>(&mut self, offset: WasmPtr<T>) -> Result<&mut T, Errno>

source§

fn mut_slice<T: Sized>( &mut self, offset: WasmPtr<T>, len: usize ) -> Result<&mut [T], Errno>

source§

fn mut_iovec( &mut self, iovec_ptr: WasmPtr<__wasi_iovec_t>, iovec_len: __wasi_size_t ) -> Result<Vec<IoSliceMut<'_>>, Errno>

source§

fn write_data<T: Sized>( &mut self, offset: WasmPtr<T>, data: T ) -> Result<(), Errno>

Auto Trait Implementations§

§

impl Freeze for Memory

§

impl RefUnwindSafe for Memory

§

impl Send for Memory

§

impl Sync for Memory

§

impl Unpin for Memory

§

impl UnwindSafe for Memory

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.