pub trait LinearMemory {
Show 20 methods
// Required methods
fn len(&self) -> usize;
fn grow_to(&mut self, new_len: usize) -> Result<(), Trap>;
fn read(&self, addr: usize, dst: &mut [u8]) -> usize;
fn write(&mut self, addr: usize, src: &[u8]) -> usize;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn write_all(&mut self, addr: usize, src: &[u8]) -> Option<()> { ... }
fn fill(&mut self, addr: usize, len: usize, val: u8) -> Option<()> { ... }
fn copy_within(&mut self, dst: usize, src: usize, len: usize) -> Option<()> { ... }
fn read_exact(&self, addr: usize, dst: &mut [u8]) -> Option<()> { ... }
fn read_vec(&self, addr: usize, len: usize) -> Option<Vec<u8>> { ... }
fn read_8(&self, base: u64, offset: u64) -> Result<u8, Trap> { ... }
fn read_16(&self, base: u64, offset: u64) -> Result<[u8; 2], Trap> { ... }
fn read_32(&self, base: u64, offset: u64) -> Result<[u8; 4], Trap> { ... }
fn read_64(&self, base: u64, offset: u64) -> Result<[u8; 8], Trap> { ... }
fn read_128(&self, base: u64, offset: u64) -> Result<[u8; 16], Trap> { ... }
fn write_8(&mut self, base: u64, offset: u64, byte: u8) -> Result<(), Trap> { ... }
fn write_16(
&mut self,
base: u64,
offset: u64,
bytes: [u8; 2],
) -> Result<(), Trap> { ... }
fn write_32(
&mut self,
base: u64,
offset: u64,
bytes: [u8; 4],
) -> Result<(), Trap> { ... }
fn write_64(
&mut self,
base: u64,
offset: u64,
bytes: [u8; 8],
) -> Result<(), Trap> { ... }
fn write_128(
&mut self,
base: u64,
offset: u64,
bytes: [u8; 16],
) -> Result<(), Trap> { ... }
}Expand description
Memory backend types and traits. Backend storage for a linear memory
This is a low-level trait that abstracts over the actual storage mechanism for linear memory.
This will probably change in the future to allow more efficient implementations.
See MemoryBackend for a higher-level interface to configuring memory storage.
Required Methods§
Sourcefn grow_to(&mut self, new_len: usize) -> Result<(), Trap>
fn grow_to(&mut self, new_len: usize) -> Result<(), Trap>
Grows the memory to new_len bytes.
The runtime only calls this with lengths that are exact multiples of the Wasm page size for the owning memory.
Sourcefn read(&self, addr: usize, dst: &mut [u8]) -> usize
fn read(&self, addr: usize, dst: &mut [u8]) -> usize
Reads up to dst.len() bytes starting at addr and returns the number of bytes read.
Backends may return fewer bytes than requested even when more data is available. This lets non-contiguous backends stop at a natural boundary such as the end of a chunk.
Sourcefn write(&mut self, addr: usize, src: &[u8]) -> usize
fn write(&mut self, addr: usize, src: &[u8]) -> usize
Writes up to src.len() bytes starting at addr and returns the number of bytes written.
Backends may return fewer bytes than requested even when more space is available. This lets non-contiguous backends stop at a natural boundary such as the end of a chunk.
Provided Methods§
Sourcefn write_all(&mut self, addr: usize, src: &[u8]) -> Option<()>
fn write_all(&mut self, addr: usize, src: &[u8]) -> Option<()>
Writes all bytes in src starting at addr, or returns None if any byte could not be written.
Sourcefn fill(&mut self, addr: usize, len: usize, val: u8) -> Option<()>
fn fill(&mut self, addr: usize, len: usize, val: u8) -> Option<()>
Fills the range [addr, addr + len) with val.
Sourcefn copy_within(&mut self, dst: usize, src: usize, len: usize) -> Option<()>
fn copy_within(&mut self, dst: usize, src: usize, len: usize) -> Option<()>
Copies len bytes from src to dst within the same memory.
Sourcefn read_exact(&self, addr: usize, dst: &mut [u8]) -> Option<()>
fn read_exact(&self, addr: usize, dst: &mut [u8]) -> Option<()>
Reads exactly dst.len() bytes starting at addr.
Sourcefn read_vec(&self, addr: usize, len: usize) -> Option<Vec<u8>>
fn read_vec(&self, addr: usize, len: usize) -> Option<Vec<u8>>
Reads len bytes starting at addr into a newly allocated buffer.
Sourcefn read_8(&self, base: u64, offset: u64) -> Result<u8, Trap>
fn read_8(&self, base: u64, offset: u64) -> Result<u8, Trap>
Reads exactly 1 byte at the effective address base + offset.
Sourcefn read_16(&self, base: u64, offset: u64) -> Result<[u8; 2], Trap>
fn read_16(&self, base: u64, offset: u64) -> Result<[u8; 2], Trap>
Reads exactly 2 bytes at the effective address base + offset.
Sourcefn read_32(&self, base: u64, offset: u64) -> Result<[u8; 4], Trap>
fn read_32(&self, base: u64, offset: u64) -> Result<[u8; 4], Trap>
Reads exactly 4 bytes at the effective address base + offset.
Sourcefn read_64(&self, base: u64, offset: u64) -> Result<[u8; 8], Trap>
fn read_64(&self, base: u64, offset: u64) -> Result<[u8; 8], Trap>
Reads exactly 8 bytes at the effective address base + offset.
Sourcefn read_128(&self, base: u64, offset: u64) -> Result<[u8; 16], Trap>
fn read_128(&self, base: u64, offset: u64) -> Result<[u8; 16], Trap>
Reads exactly 16 bytes at the effective address base + offset.
Sourcefn write_8(&mut self, base: u64, offset: u64, byte: u8) -> Result<(), Trap>
fn write_8(&mut self, base: u64, offset: u64, byte: u8) -> Result<(), Trap>
Writes exactly 1 byte at the effective address base + offset.
Sourcefn write_16(
&mut self,
base: u64,
offset: u64,
bytes: [u8; 2],
) -> Result<(), Trap>
fn write_16( &mut self, base: u64, offset: u64, bytes: [u8; 2], ) -> Result<(), Trap>
Writes exactly 2 bytes at the effective address base + offset.
Sourcefn write_32(
&mut self,
base: u64,
offset: u64,
bytes: [u8; 4],
) -> Result<(), Trap>
fn write_32( &mut self, base: u64, offset: u64, bytes: [u8; 4], ) -> Result<(), Trap>
Writes exactly 4 bytes at the effective address base + offset.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".