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

Method read

crates/wasmtime/src/runtime/memory.rs:354–368  ·  view source on GitHub ↗

Safely reads memory contents at the given offset into a buffer. The entire buffer will be filled. If `offset + buffer.len()` exceed the current memory capacity, then the buffer is left untouched and a [`MemoryAccessError`] is returned. # Errors This function will return an [`OutOfMemory`][crate::OutOfMemory] error when memory allocation fails. See the `OutOfMemory` type's documentation for det

(
        &self,
        store: impl AsContext,
        offset: usize,
        buffer: &mut [u8],
    )

Source from the content-addressed store, hash-verified

352 ///
353 /// Panics if this memory doesn't belong to `store`.
354 pub fn read(
355 &self,
356 store: impl AsContext,
357 offset: usize,
358 buffer: &mut [u8],
359 ) -> Result<(), MemoryAccessError> {
360 let store = store.as_context();
361 let slice = self
362 .data(&store)
363 .get(offset..)
364 .and_then(|s| s.get(..buffer.len()))
365 .ok_or(MemoryAccessError { _private: () })?;
366 buffer.copy_from_slice(slice);
367 Ok(())
368 }
369
370 /// Safely writes contents of a buffer to this memory at the given offset.
371 ///

Callers 7

rootMethod · 0.45
debug_assert_containsMethod · 0.45
borrowMethod · 0.45
layoutMethod · 0.45
trampoline_typeMethod · 0.45
is_subtypeMethod · 0.45
is_subtype_slowMethod · 0.45

Calls 6

OkFunction · 0.85
as_contextMethod · 0.45
getMethod · 0.45
dataMethod · 0.45
lenMethod · 0.45
copy_from_sliceMethod · 0.45

Tested by

no test coverage detected