Trait Memory

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

    // Provided method
    unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize) { ... }
}

Required Methods§

Source

fn size(&self) -> u64

Returns the current size of the stable memory in WebAssembly pages. (One WebAssembly page is 64Ki bytes.)

Source

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

Tries to grow the memory by pages many pages containing zeroes. If successful, returns the previous size of the memory (in pages). Otherwise, returns -1.

Source

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

Copies the data referred to by offset out of the stable memory and replaces the corresponding bytes in dst.

Source

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

Copies the data referred to by src and replaces the corresponding segment starting at offset in the stable memory.

Provided Methods§

Source

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Copies count number of bytes of the data starting from offset out of the stable memory into the buffer starting at dst.

This method is an alternative to read which does not require initializing a buffer and may therefore be faster.

§Safety

Callers must guarantee that

  • it is valid to write count number of bytes starting from dst,
  • dst..dst + count does not overlap with self.

Implementations must guarantee that before the method returns, count number of bytes starting from dst will be initialized.

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, dst: &mut [u8])

Source§

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Source§

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

Source§

impl<M: Memory> Memory for Rc<M>

Source§

fn size(&self) -> u64

Source§

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

Source§

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

Source§

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Source§

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

Implementors§