Struct wasmer_wasix::syscalls::WasmSlice
pub(crate) struct WasmSlice<'a, T>where
T: ValueType,{
pub(crate) buffer: MemoryBuffer<'a>,
pub(crate) offset: u64,
pub(crate) len: u64,
marker: PhantomData<*mut T>,
}
Expand description
Reference to an array of values in Wasm memory.
The type of the value must satisfy the requirements of the ValueType
trait which guarantees that reading and writing such a value to untrusted
memory is safe.
The address is not required to be aligned: unaligned accesses are fully supported.
This wrapper safely handles concurrent modifications of the data by another thread.
Fields§
§buffer: MemoryBuffer<'a>
§offset: u64
§len: u64
§marker: PhantomData<*mut T>
Implementations§
§impl<'a, T> WasmSlice<'a, T>where
T: ValueType,
impl<'a, T> WasmSlice<'a, T>where
T: ValueType,
pub fn new(
view: &'a MemoryView<'_>,
offset: u64,
len: u64,
) -> Result<WasmSlice<'a, T>, MemoryAccessError>
pub fn new( view: &'a MemoryView<'_>, offset: u64, len: u64, ) -> Result<WasmSlice<'a, T>, MemoryAccessError>
Creates a new WasmSlice
starting at the given offset in memory and
with the given number of elements.
Returns a MemoryAccessError
if the slice length overflows.
pub fn subslice(self, range: Range<u64>) -> WasmSlice<'a, T>
pub fn subslice(self, range: Range<u64>) -> WasmSlice<'a, T>
Get a WasmSlice
for a subslice of this slice.
pub fn iter(self) -> WasmSliceIter<'a, T>
pub fn iter(self) -> WasmSliceIter<'a, T>
Get an iterator over the elements in this slice.
pub fn access(self) -> Result<WasmSliceAccess<'a, T>, MemoryAccessError>
pub fn access(self) -> Result<WasmSliceAccess<'a, T>, MemoryAccessError>
Gains direct access to the memory of this slice
pub fn read(self, idx: u64) -> Result<T, MemoryAccessError>
pub fn read(self, idx: u64) -> Result<T, MemoryAccessError>
Reads an element of this slice.
pub fn write(self, idx: u64, val: T) -> Result<(), MemoryAccessError>
pub fn write(self, idx: u64, val: T) -> Result<(), MemoryAccessError>
Writes to an element of this slice.
pub fn read_slice(self, buf: &mut [T]) -> Result<(), MemoryAccessError>
pub fn read_slice(self, buf: &mut [T]) -> Result<(), MemoryAccessError>
Reads the entire slice into the given buffer.
The length of the buffer must match the length of the slice.
pub fn read_slice_uninit(
self,
buf: &mut [MaybeUninit<T>],
) -> Result<&mut [T], MemoryAccessError>
pub fn read_slice_uninit( self, buf: &mut [MaybeUninit<T>], ) -> Result<&mut [T], MemoryAccessError>
Reads the entire slice into the given uninitialized buffer.
The length of the buffer must match the length of the slice.
This method returns an initialized view of the buffer.
pub fn write_slice(self, data: &[T]) -> Result<(), MemoryAccessError>
pub fn write_slice(self, data: &[T]) -> Result<(), MemoryAccessError>
Write the given slice into this WasmSlice
.
The length of the slice must match the length of the WasmSlice
.
pub fn read_to_slice(
self,
buf: &mut [MaybeUninit<u8>],
) -> Result<usize, MemoryAccessError>
pub fn read_to_slice( self, buf: &mut [MaybeUninit<u8>], ) -> Result<usize, MemoryAccessError>
Reads this WasmSlice
into a slice
.
pub fn read_to_vec(self) -> Result<Vec<T>, MemoryAccessError>
pub fn read_to_vec(self) -> Result<Vec<T>, MemoryAccessError>
Reads this WasmSlice
into a Vec
.
pub fn read_to_bytes(self) -> Result<BytesMut, MemoryAccessError>
pub fn read_to_bytes(self) -> Result<BytesMut, MemoryAccessError>
Reads this WasmSlice
into a BytesMut
Trait Implementations§
impl<'a, T> Copy for WasmSlice<'a, T>where
T: Copy + ValueType,
Auto Trait Implementations§
impl<'a, T> Freeze for WasmSlice<'a, T>
impl<'a, T> RefUnwindSafe for WasmSlice<'a, T>where
T: RefUnwindSafe,
impl<'a, T> !Send for WasmSlice<'a, T>
impl<'a, T> !Sync for WasmSlice<'a, T>
impl<'a, T> Unpin for WasmSlice<'a, T>
impl<'a, T> UnwindSafe for WasmSlice<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more