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

Method write

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

Safely writes contents of a buffer to this memory at the given offset. If the `offset + buffer.len()` exceeds the current memory capacity, then none of the buffer is written to memory 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 details on Wasm

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

Source from the content-addressed store, hash-verified

383 ///
384 /// Panics if this memory doesn't belong to `store`.
385 pub fn write(
386 &self,
387 mut store: impl AsContextMut,
388 offset: usize,
389 buffer: &[u8],
390 ) -> Result<(), MemoryAccessError> {
391 let mut context = store.as_context_mut();
392 self.data_mut(&mut context)
393 .get_mut(offset..)
394 .and_then(|s| s.get_mut(..buffer.len()))
395 .ok_or(MemoryAccessError { _private: () })?
396 .copy_from_slice(buffer);
397 Ok(())
398 }
399
400 /// Returns this memory as a native Rust slice.
401 ///

Callers 7

newFunction · 0.45
store_untyped_resultsMethod · 0.45
dropMethod · 0.45
newMethod · 0.45
storeMethod · 0.45
init_gc_refMethod · 0.45

Calls 6

OkFunction · 0.85
as_context_mutMethod · 0.45
copy_from_sliceMethod · 0.45
get_mutMethod · 0.45
data_mutMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected