Struct Memory

Source
pub struct Memory { /* private fields */ }
Expand description

A shared or unshared wasm linear memory.

A Memory represents the memory used by a wasm instance.

Implementations§

Source§

impl Memory

Source

pub fn new(desc: MemoryDescriptor) -> Result<Self, CreationError>

Create a new Memory from a MemoryDescriptor

Usage:

fn create_memory() -> Result<()> {
    let descriptor = MemoryDescriptor::new(Pages(10), None, false).unwrap();

    let memory = Memory::new(descriptor)?;
    Ok(())
}
Source

pub fn descriptor(&self) -> MemoryDescriptor

Return the MemoryDescriptor that this memory was created with.

Source

pub fn grow(&self, delta: Pages) -> Result<Pages, GrowError>

Grow this memory by the specified number of pages.

Source

pub fn size(&self) -> Pages

The size, in wasm pages, of this memory.

Source

pub fn view<T: ValueType>(&self) -> MemoryView<'_, T>

Return a “view” of the currently accessible memory. By default, the view is unsynchronized, using regular memory accesses. You can force a memory view to use atomic accesses by calling the atomically method.

§Notes:

This method is safe (as in, it won’t cause the host to crash or have UB), but it doesn’t obey rust’s rules involving data races, especially concurrent ones. Therefore, if this memory is shared between multiple threads, a single memory location can be mutated concurrently without synchronization.

§Usage:
// Without synchronization.
let view: MemoryView<u8> = memory.view();
for byte in view[0x1000 .. 0x1010].iter().map(Cell::get) {
    println!("byte: {}", byte);
}

// With synchronization.
let atomic_view = view.atomically();
for byte in atomic_view[0x1000 .. 0x1010].iter().map(|atom| atom.load(Ordering::SeqCst)) {
    println!("byte: {}", byte);
}

Trait Implementations§

Source§

impl Clone for Memory

Source§

fn clone(&self) -> Memory

Returns a duplicate 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
Source§

impl<'a> Exportable<'a> for Memory

Source§

fn get_self(exports: &'a Exports, name: &str) -> ResolveResult<Self>

Implementation of how to get the export corresponding to the implementing type from an [Instance] by name.
Source§

impl IsExport for Memory

Source§

fn to_export(&self) -> Export

Gets self as Export.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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