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(&mut self, offset: u64, buf: &mut [u8]) -> MemoryResult<()>;
fn write(&mut self, offset: u64, buf: &[u8]) -> MemoryResult<()>;
// Provided method
fn flush(&mut self) -> 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 in bytes that was reserved.
Actual reserved size after the growth will be previous_size + (new_pages * PAGE_SIZE).
Provided Methods§
Sourcefn flush(&mut self) -> MemoryResult<()>
fn flush(&mut self) -> MemoryResult<()>
Publishes pending changes to the provider’s durable storage.
Providers without an explicit persistence boundary use the default no-op implementation. This hook does not flush active transaction overlays held by the DBMS context.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".