MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / as_slice

Method as_slice

crates/wiggle/src/lib.rs:131–137  ·  view source on GitHub ↗

Attempts to borrow a raw guest slice of memory pointed to by `ptr`. This method will attempt to return a raw pointer into guest memory. This can only be done for `Unshared` memories. A `Shared` memory will return `Ok(None)` here. # Errors An error is returned if `ptr` is out of bounds, misaligned, or otherwise not valid to read from.

(&self, ptr: GuestPtr<[u8]>)

Source from the content-addressed store, hash-verified

129 /// An error is returned if `ptr` is out of bounds, misaligned, or otherwise
130 /// not valid to read from.
131 pub fn as_slice(&self, ptr: GuestPtr<[u8]>) -> Result<Option<&[u8]>, GuestError> {
132 let range = self.validate_range::<u8>(ptr.pointer.0, ptr.pointer.1)?;
133 match self {
134 GuestMemory::Unshared(slice) => Ok(Some(&slice[range])),
135 GuestMemory::Shared(_) => Ok(None),
136 }
137 }
138
139 /// Same as [`GuestMemory::as_slice`] but for strings.
140 pub fn as_str(&self, ptr: GuestPtr<str>) -> Result<Option<&str>, GuestError> {

Callers 15

is_simpleMethod · 0.45
buildMethod · 0.45
build_with_localsMethod · 0.45
canonicalise_v128_valuesFunction · 0.45
as_cowMethod · 0.45
as_strMethod · 0.45
loadMethod · 0.45
loadMethod · 0.45
computeMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
handle_eventMethod · 0.45

Calls 1

OkFunction · 0.85

Tested by 5

test_file_pread_pwriteFunction · 0.36
test_file_read_writeFunction · 0.36
test_file_long_writeFunction · 0.36
fromMethod · 0.36