pub struct WasmSlice<'a, T: ValueType> { /* private fields */ }
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.
Implementations
sourceimpl<'a, T: ValueType> WasmSlice<'a, T>
impl<'a, T: ValueType> WasmSlice<'a, T>
sourcepub fn new(
view: &'a MemoryView<'_>,
offset: u64,
len: u64
) -> Result<Self, MemoryAccessError>
pub fn new(
view: &'a MemoryView<'_>,
offset: u64,
len: u64
) -> Result<Self, 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.
sourcepub 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.
sourcepub fn iter(self) -> WasmSliceIter<'a, T>ⓘNotable traits for WasmSliceIter<'a, T>impl<'a, T: ValueType> Iterator for WasmSliceIter<'a, T> type Item = WasmRef<'a, T>;
pub fn iter(self) -> WasmSliceIter<'a, T>ⓘNotable traits for WasmSliceIter<'a, T>impl<'a, T: ValueType> Iterator for WasmSliceIter<'a, T> type Item = WasmRef<'a, T>;
Get an iterator over the elements in this slice.
sourcepub fn read(self, idx: u64) -> Result<T, MemoryAccessError>
pub fn read(self, idx: u64) -> Result<T, MemoryAccessError>
Reads an element of this slice.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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
.
sourcepub 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
.
Trait Implementations
impl<'a, T: Copy + ValueType> Copy for WasmSlice<'a, T>
Auto Trait Implementations
impl<'a, T> !RefUnwindSafe for WasmSlice<'a, T>
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>
Blanket Implementations
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more