Struct wasmedge_sdk::Memory

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

Defines a linear memory.

Implementations§

source§

impl Memory

source

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

Creates a new wasm memory instance with the given type.

Argument
  • ty - The type of the memory instance to be created.
Error
source

pub fn name(&self) -> Option<&str>

Returns the exported name of this memory.

Notice that this field is meaningful only if this memory is used as an exported instance.

source

pub fn mod_name(&self) -> Option<&str>

Returns the name of the module instance from which this memory exports.

Notice that this field is meaningful only if this memory is used as an exported instance.

source

pub fn ty(&self) -> &MemoryType

Returns a reference to the type of this memory.

source

pub fn page(&self) -> u32

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

source

pub fn size(&self) -> u64

Returns the byte length of this memory. The returned value will be a multiple of the wasm page size, 64k.

source

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

Safely reads memory contents at the given offset into a buffer.

Arguments
  • offset - The offset from which to read.

  • len - the length of bytes to read.

Error

If fail to read the memory, then an error is returned.

source

pub fn read_string(&self, offset: u32, len: u32) -> WasmEdgeResult<String>

Returns a string of byte length len from this memory, starting at offset.

Arguments
  • offset - The offset from which to read.

  • len - the length of bytes to read.

Error

If fail to read, then an error is returned.

source

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

Safely writes contents of a buffer to this memory at the given offset.

Arguments
  • data - The bytes to write to this memory..

  • offset - The offset at which to write.

Error

If fail to write to the memory, then an error is returned.

source

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

Grows this memory by the count pages.

Argument
  • count - The number of pages to grow the memory by.
Error

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

source

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

Returns the const data pointer to this memory.

Arguments
  • offset - The data start offset in this memory.

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

Errors

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

source

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

Returns the data pointer to this memory.

Arguments
  • offset - The data start offset in this memory.

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

Errors

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

Trait Implementations§

source§

impl Clone for Memory

source§

fn clone(&self) -> Memory

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Memory

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V