Skip to main content

Memory

Trait Memory 

Source
pub trait Memory {
    // Required methods
    fn size(&self) -> u64;
    fn grow(&self, pages: u64) -> i64;
    fn read(&self, offset: u64, bytes: &mut [u8]);
    fn write(&self, offset: u64, bytes: &[u8]);
}
Expand description

Memory

Page-addressed storage with initialized reads and nonshrinking capacity. Implementations validate complete access ranges before touching backing bytes.

Required Methods§

Source

fn size(&self) -> u64

Returns the number of complete accessible Wasm pages.

Source

fn grow(&self, pages: u64) -> i64

Adds zero-filled pages, returning the previous size or -1 on refusal. Refusal leaves the existing bytes and extent unchanged.

Source

fn read(&self, offset: u64, bytes: &mut [u8])

Copies the selected backing bytes into an initialized destination.

§Panics

Panics or traps if the complete range is outside the backing.

Source

fn write(&self, offset: u64, bytes: &[u8])

Replaces the selected backing bytes.

§Panics

Panics or traps if the complete range is outside the backing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Memory for RefCell<Vec<u8>>

Source§

fn size(&self) -> u64

Source§

fn grow(&self, pages: u64) -> i64

Source§

fn read(&self, offset: u64, bytes: &mut [u8])

Source§

fn write(&self, offset: u64, bytes: &[u8])

Source§

impl<M: Memory + ?Sized> Memory for &M

Source§

fn size(&self) -> u64

Source§

fn grow(&self, pages: u64) -> i64

Source§

fn read(&self, offset: u64, bytes: &mut [u8])

Source§

fn write(&self, offset: u64, bytes: &[u8])

Source§

impl<M: Memory + ?Sized> Memory for Rc<M>

Source§

fn size(&self) -> u64

Source§

fn grow(&self, pages: u64) -> i64

Source§

fn read(&self, offset: u64, bytes: &mut [u8])

Source§

fn write(&self, offset: u64, bytes: &[u8])

Implementors§