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]);
// Provided method
unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize) { ... }
}Expand description
Memory
Page-addressed storage with initialized reads and nonshrinking capacity. Implementations validate complete access ranges before touching backing bytes.
Required Methods§
Sourcefn grow(&self, pages: u64) -> i64
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.
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)
Initializes the destination from the selected backing bytes.
The default implementation admits the entire source range, then reads through a bounded, initialized scratch buffer. Custom backings pay an additional copy per chunk; direct implementations can override this. Failure may leave an initialized prefix in the destination.
§Safety
dst must satisfy the validity, alignment, and exclusive writable access
requirements of a Rust slice of count bytes, including for zero length.
That destination must not overlap the source or the backing’s own state.
§Panics
Panics or traps if the complete source range is outside the backing or if the backing’s safe read fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".