pub struct Memory(/* private fields */);Expand description
Newtype wrapper around wasmer::Memory.
Implementations§
Source§impl Memory
impl Memory
Sourcepub fn new(inner: Memory) -> Self
pub fn new(inner: Memory) -> Self
Create a wasm_runtime_layer::Memory-compatible Memory from a wasmer::Memory.
Sourcepub fn into_inner(self) -> Memory
pub fn into_inner(self) -> Memory
Consume a Memory to obtain the inner wasmer::Memory.
Methods from Deref<Target = Memory>§
Sourcepub fn as_sys(&self) -> &Memory
pub fn as_sys(&self) -> &Memory
Convert a reference to self into a reference to crate::backend::sys::memory::Memory.
Sourcepub fn as_sys_mut(&mut self) -> &mut Memory
pub fn as_sys_mut(&mut self) -> &mut Memory
Convert a mutable reference to self into a mutable reference to crate::backend::sys::memory::Memory.
Sourcepub fn ty(&self, store: &impl AsStoreRef) -> MemoryType
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);Sourcepub fn view<'a>(&self, store: &'a (impl AsStoreRef + ?Sized)) -> MemoryView<'a>
pub fn view<'a>(&self, store: &'a (impl AsStoreRef + ?Sized)) -> MemoryView<'a>
Creates a view into the memory that then allows for read and write
Sourcepub fn size(&self, store: &impl AsStoreRef) -> Pages
pub fn size(&self, store: &impl AsStoreRef) -> Pages
Retrieve the size of the memory in pages.
Sourcepub fn grow<IntoPages>(
&self,
store: &mut impl AsStoreMut,
delta: IntoPages,
) -> Result<Pages, MemoryError>
pub fn grow<IntoPages>( &self, store: &mut impl AsStoreMut, delta: IntoPages, ) -> Result<Pages, MemoryError>
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();Sourcepub fn grow_at_least(
&self,
store: &mut impl AsStoreMut,
min_size: u64,
) -> Result<(), MemoryError>
pub fn grow_at_least( &self, store: &mut impl AsStoreMut, min_size: u64, ) -> Result<(), MemoryError>
Grows the memory to at least a minimum size.
§Note
If the memory is already big enough for the min size this function does nothing.
Sourcepub fn reset(&self, store: &mut impl AsStoreMut) -> Result<(), MemoryError>
pub fn reset(&self, store: &mut impl AsStoreMut) -> Result<(), MemoryError>
Resets the memory back to zero length
Sourcepub fn copy_to_store(
&self,
store: &impl AsStoreRef,
new_store: &mut impl AsStoreMut,
) -> Result<Memory, MemoryError>
pub fn copy_to_store( &self, store: &impl AsStoreRef, new_store: &mut impl AsStoreMut, ) -> Result<Memory, MemoryError>
Attempts to duplicate this memory (if its clonable) in a new store (copied memory)
Sourcepub fn is_from_store(&self, store: &impl AsStoreRef) -> bool
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool
Checks whether this Memory can be used with the given context.
Sourcepub fn try_clone(
&self,
store: &impl AsStoreRef,
) -> Result<VMMemory, MemoryError>
pub fn try_clone( &self, store: &impl AsStoreRef, ) -> Result<VMMemory, MemoryError>
Attempt to create a new reference to the underlying memory; this new reference can then be used within a different store (from the same implementer).
§Errors
Fails if the underlying memory is not clonable.
Attempts to clone this memory (if its clonable) in a new store (cloned memory will be shared between those that clone it)
Get a SharedMemory.
Only returns Some(_) if the memory is shared, and if the target
backend supports shared memory operations.
See SharedMemory and its methods for more information.
Trait Implementations§
Source§impl WasmMemory<Engine> for Memory
impl WasmMemory<Engine> for Memory
Source§fn new(ctx: impl AsContextMut<Engine>, ty: MemoryType) -> Result<Self>
fn new(ctx: impl AsContextMut<Engine>, ty: MemoryType) -> Result<Self>
Source§fn ty(&self, ctx: impl AsContext<Engine>) -> MemoryType
fn ty(&self, ctx: impl AsContext<Engine>) -> MemoryType
Source§fn grow(&self, ctx: impl AsContextMut<Engine>, additional: u32) -> Result<u32>
fn grow(&self, ctx: impl AsContextMut<Engine>, additional: u32) -> Result<u32>
Source§fn current_pages(&self, ctx: impl AsContext<Engine>) -> u32
fn current_pages(&self, ctx: impl AsContext<Engine>) -> u32
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.