wasmedge_sys

Struct 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>,

Source§

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>,

Source§

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.