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 with UnsafeGuestSlice::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 and GuestSliceMut smart pointers (see UnsafeGuestSlice::shared_borrow, UnsafeGuestSlice::mut_borrow).

Implementations§

source§

impl<'a, T> UnsafeGuestSlice<'a, T>

source

pub fn copy_from_slice(self, slice: &[T]) -> Result<(), GuestError>
where T: GuestTypeTransparent<'a> + Copy + 'a,

See GuestPtr::copy_from_slice.

source

pub fn len(&self) -> usize

Return the number of items in this slice.

source

pub fn is_shared_memory(&self) -> bool

Check if this slice comes from WebAssembly shared memory.

source

pub fn as_slice_mut(self) -> Result<Option<GuestSliceMut<'a, T>>, GuestError>
where T: GuestTypeTransparent<'a>,

See GuestPtr::as_slice_mut.

Trait Implementations§

source§

impl<T: Send> Send for UnsafeGuestSlice<'_, T>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointee for T

§

type Pointer = u32

source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_> ) -> Result<(), Error>

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more