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],
)
| 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 | /// |
no test coverage detected