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§
Sourcefn size(&self) -> u64
fn size(&self) -> u64
Returns the current size of the stable memory in WebAssembly pages. (One WebAssembly page is 64Ki bytes.)
Sourcefn grow(&self, pages: u64) -> i64
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.
Provided Methods§
Sourceunsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)
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
countnumber of bytes starting fromdst, dst..dst + countdoes not overlap withself.
Implementations must guarantee that before the method returns, count number of bytes
starting from dst will be initialized.