Added back Memory::data_unchecked and Memory::data_unchecked_mut as hidden (for wit-bindgen)

This commit is contained in:
ptitSeb
2022-07-13 15:46:42 +02:00
committed by Manos Pitsidianakis
parent a419ccdf52
commit 97732351d4

View File

@@ -86,6 +86,33 @@ impl Memory {
self.buffer(ctx).len.try_into().unwrap()
}
/// Retrieve a slice of the memory contents.
///
/// # Safety
///
/// Until the returned slice is dropped, it is undefined behaviour to
/// modify the memory contents in any way including by calling a wasm
/// function that writes to the memory or by resizing the memory.
#[doc(hidden)]
pub unsafe fn data_unchecked(&self, ctx: &impl AsStoreRef) -> &[u8] {
self.data_unchecked_mut(ctx)
}
/// Retrieve a mutable slice of the memory contents.
///
/// # Safety
///
/// This method provides interior mutability without an UnsafeCell. Until
/// the returned value is dropped, it is undefined behaviour to read or
/// write to the pointed-to memory in any way except through this slice,
/// including by calling a wasm function that reads the memory contents or
/// by resizing this Memory.
#[allow(clippy::mut_from_ref)]
#[doc(hidden)]
pub unsafe fn data_unchecked_mut(&self, ctx: &impl AsStoreRef) -> &mut [u8] {
slice::from_raw_parts_mut(self.buffer(ctx).base, self.buffer(ctx).len)
}
/// Returns the size (in [`Pages`]) of the `Memory`.
///
/// # Example