Struct wiggle::UnsafeGuestSlice
source · pub struct UnsafeGuestSlice<'a, T> { /* private fields */ }
Expand description
A smart pointer to an unsafe
slice in guest memory.
Accessing guest memory (e.g., WebAssembly linear memory) is inherently
unsafe
. Even though this structure expects that we will have validated the
addresses, lengths, and alignment, we must be extra careful to maintain the
Rust borrowing guarantees if we hand out slices to the underlying memory.
This is done in two ways:
- with shared memory (i.e., memory that may be accessed concurrently by
multiple threads), we have no guarantee that the underlying data will not
be changed; thus, we can only hand out slices
unsafe
-ly (TODO: eventually withUnsafeGuestSlice::as_slice
,UnsafeGuestSlice::as_slice_mut
) - with non-shared memory, we can maintain the Rust slice guarantees, but
only by manually performing borrow-checking of the underlying regions that
are accessed; this kind of borrowing is wrapped up in the
GuestSlice
andGuestSliceMut
smart pointers (seeUnsafeGuestSlice::shared_borrow
,UnsafeGuestSlice::mut_borrow
).
Implementations§
source§impl<'a, T> UnsafeGuestSlice<'a, T>
impl<'a, T> UnsafeGuestSlice<'a, T>
sourcepub fn copy_from_slice(self, slice: &[T]) -> Result<(), GuestError>where
T: GuestTypeTransparent<'a> + Copy + 'a,
pub fn copy_from_slice(self, slice: &[T]) -> Result<(), GuestError>where
T: GuestTypeTransparent<'a> + Copy + 'a,
See GuestPtr::copy_from_slice
.
Check if this slice comes from WebAssembly shared memory.
sourcepub fn as_slice_mut(self) -> Result<Option<GuestSliceMut<'a, T>>, GuestError>where
T: GuestTypeTransparent<'a>,
pub fn as_slice_mut(self) -> Result<Option<GuestSliceMut<'a, T>>, GuestError>where
T: GuestTypeTransparent<'a>,
See GuestPtr::as_slice_mut
.
Trait Implementations§
impl<T: Send> Send for UnsafeGuestSlice<'_, T>
impl<T: Sync> Sync for UnsafeGuestSlice<'_, T>
Auto Trait Implementations§
impl<'a, T> !RefUnwindSafe for UnsafeGuestSlice<'a, T>
impl<'a, T> Unpin for UnsafeGuestSlice<'a, T>
impl<'a, T> !UnwindSafe for UnsafeGuestSlice<'a, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more