pub unsafe trait LinearMemory:
Send
+ Sync
+ 'static {
// Required methods
fn byte_size(&self) -> usize;
fn byte_capacity(&self) -> usize;
fn grow_to(&mut self, new_size: usize) -> Result<()>;
fn as_ptr(&self) -> *mut u8;
}runtime only.Expand description
A linear memory. This trait provides an interface for raw memory buffers which are used by wasmtime, e.g. inside [‘Memory’]. Such buffers are in principle not thread safe. By implementing this trait together with MemoryCreator, one can supply wasmtime with custom allocated host managed memory.
§Safety
The memory should be page aligned and a multiple of page size. To prevent possible silent overflows, the memory should be protected by a guard page. Additionally the safety concerns explained in [‘Memory’], for accessing the memory apply here as well.
The value returned by LinearMemory::byte_size must be at least the
minimum size the memory was created with, must be at least new_size
after a successful LinearMemory::grow_to, and must never decrease.
At least that many bytes starting at LinearMemory::as_ptr must be
valid to read and write. Compiled WebAssembly code relies on these
properties when performing bounds checks, so violating them can lead to
out-of-bounds memory accesses.
Note that this is a relatively advanced feature and it is recommended to be familiar with wasmtime runtime code to use it.
Required Methods§
Sourcefn byte_size(&self) -> usize
fn byte_size(&self) -> usize
Returns the number of allocated bytes which are accessible at this time.
Sourcefn byte_capacity(&self) -> usize
fn byte_capacity(&self) -> usize
Returns byte capacity of this linear memory’s current allocation.
Growth up to this value should not relocate the linear memory base pointer.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".