Struct wasmer::Memory

source ·
pub struct Memory(_);
Expand description

A WebAssembly memory instance.

A memory instance is the runtime representation of a linear memory. It consists of a vector of bytes and an optional maximum size.

The length of the vector always is a multiple of the WebAssembly page size, which is defined to be the constant 65536 – abbreviated 64Ki. Like in a memory type, the maximum size in a memory instance is given in units of this page size.

A memory created by the host or in WebAssembly code will be accessible and mutable from both host and WebAssembly.

Spec: https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances

Implementations§

source§

impl Memory

source

pub fn new( store: &mut impl AsStoreMut, ty: MemoryType ) -> Result<Self, MemoryError>

Creates a new host Memory from the provided MemoryType.

This function will construct the Memory using the store BaseTunables.

Example
let m = Memory::new(&mut store, MemoryType::new(1, None, false)).unwrap();
source

pub fn new_from_existing( new_store: &mut impl AsStoreMut, memory: VMMemory ) -> Self

Create a memory object from an existing memory and attaches it to the store

source

pub fn ty(&self, store: &impl AsStoreRef) -> MemoryType

Returns the MemoryType of the Memory.

Example
let mt = MemoryType::new(1, None, false);
let m = Memory::new(&mut store, mt).unwrap();

assert_eq!(m.ty(&mut store), mt);
source

pub fn view<'a>(&self, store: &'a impl AsStoreRef) -> MemoryView<'a>

Creates a view into the memory that then allows for read and write

source

pub fn grow<IntoPages>( &self, store: &mut impl AsStoreMut, delta: IntoPages ) -> Result<Pages, MemoryError>where IntoPages: Into<Pages>,

Grow memory by the specified amount of WebAssembly Pages and return the previous memory size.

Example
let m = Memory::new(&mut store, MemoryType::new(1, Some(3), false)).unwrap();
let p = m.grow(&mut store, 2).unwrap();

assert_eq!(p, Pages(1));
assert_eq!(m.view(&mut store).size(), Pages(3));
Errors

Returns an error if memory can’t be grown by the specified amount of pages.

let m = Memory::new(&mut store, MemoryType::new(1, Some(1), false)).unwrap();

// This results in an error: `MemoryError::CouldNotGrow`.
let s = m.grow(&mut store, 1).unwrap();
source

pub fn copy_to_store( &self, store: &impl AsStoreRef, new_store: &mut impl AsStoreMut ) -> Result<Self, MemoryError>

Copies the memory to a new store and returns a memory reference to it

source

pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool

Checks whether this Memory can be used with the given context.

source

pub fn try_clone(&self, store: &impl AsStoreRef) -> Option<VMMemory>

Attempts to clone this memory (if its clonable)

source

pub fn clone_in_store( &self, store: &impl AsStoreRef, new_store: &mut impl AsStoreMut ) -> Option<Self>

Attempts to clone this memory (if its clonable) in a new store

source

pub fn duplicate_in_store( &self, store: &impl AsStoreRef, new_store: &mut impl AsStoreMut ) -> Option<Self>

Attempts to duplicate this memory (if its clonable) in a new store

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
source§

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

source§

fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError>

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

impl From<Memory> for Extern

source§

fn from(r: Memory) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Memory> for Memory

source§

fn eq(&self, other: &Memory) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Memory

source§

impl StructuralPartialEq for Memory

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
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.
source§

impl<T> Upcastable for Twhere T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

upcast boxed dyn
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more