pub trait MemoryProvider {
const PAGE_SIZE: u64;
// Required methods
fn size(&self) -> u64;
fn pages(&self) -> u64;
fn grow(&mut self, new_pages: u64) -> MemoryResult<u64>;
fn read(&self, offset: u64, buf: &mut [u8]) -> MemoryResult<()>;
fn write(&mut self, offset: u64, buf: &[u8]) -> MemoryResult<()>;
}Expand description
Memory Provider trait defines the interface for interacting with the underlying memory.
Abstracting memory access allows different implementations for production (e.g. stable memory) and testing (heap-based).
Required Associated Constants§
Required Methods§
Sourcefn grow(&mut self, new_pages: u64) -> MemoryResult<u64>
fn grow(&mut self, new_pages: u64) -> MemoryResult<u64>
Attempts to grow the memory by new_pages (added pages).
Returns an error if it wasn’t possible. Otherwise, returns the previous size that was reserved.
Actual reserved size after the growth will be previous_size + (new_pages * PAGE_SIZE).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.