pub trait Memory {
// Required methods
fn with_access_mut<R>(&mut self, run: impl FnOnce(&mut [u8]) -> R) -> R;
fn with_access<R>(&self, run: impl FnOnce(&[u8]) -> R) -> R;
fn grow(&mut self, additional: u32) -> Result<(), ()>;
fn pages(&self) -> u32;
fn max_pages(&self) -> Option<u32>;
}
Expand description
Grants access to the memory for the allocator.
Memory of wasm is allocated in pages. A page has a constant size of 64KiB. The maximum allowed memory size as defined in the wasm specification is 4GiB (65536 pages).
Required Methods§
Sourcefn with_access_mut<R>(&mut self, run: impl FnOnce(&mut [u8]) -> R) -> R
fn with_access_mut<R>(&mut self, run: impl FnOnce(&mut [u8]) -> R) -> R
Run the given closure run
and grant it write access to the raw memory.
Sourcefn with_access<R>(&self, run: impl FnOnce(&[u8]) -> R) -> R
fn with_access<R>(&self, run: impl FnOnce(&[u8]) -> R) -> R
Run the given closure run
and grant it read access to the raw memory.
Sourcefn max_pages(&self) -> Option<u32>
fn max_pages(&self) -> Option<u32>
Returns the maximum number of pages this memory is allowed to allocate.
The returned number needs to be smaller or equal to 65536
. The returned number needs to be
bigger or equal to Self::pages
.
If None
is returned, there is no maximum (besides the maximum defined in the wasm spec).
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.