pub struct WasmRef<'a, T: ValueType> {
pub(crate) buffer: MemoryBuffer<'a>,
pub(crate) offset: u64,
marker: PhantomData<*mut T>,
}
Expand description
Reference to a value 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 required to be aligned: unaligned accesses cause undefined behavior.
This wrapper safely handles concurrent modifications of the data by another thread.
Fields§
§buffer: MemoryBuffer<'a>
§offset: u64
§marker: PhantomData<*mut T>
Implementations§
source§impl<'a, T: ValueType> WasmRef<'a, T>
impl<'a, T: ValueType> WasmRef<'a, T>
sourcepub fn new(view: &'a MemoryView<'_>, offset: u64) -> Self
pub fn new(view: &'a MemoryView<'_>, offset: u64) -> Self
Creates a new WasmRef
at the given offset in a memory.
sourcepub fn as_ptr<M: MemorySize>(self) -> WasmPtr<T, M>
pub fn as_ptr<M: MemorySize>(self) -> WasmPtr<T, M>
Get a WasmPtr
for this WasmRef
.
sourcepub fn read(self) -> Result<T, MemoryAccessError>
pub fn read(self) -> Result<T, MemoryAccessError>
Reads the location pointed to by this WasmRef
.
sourcepub fn write(self, val: T) -> Result<(), MemoryAccessError>
pub fn write(self, val: T) -> Result<(), MemoryAccessError>
Writes to the location pointed to by this WasmRef
.
sourcepub fn access(self) -> Result<WasmRefAccess<'a, T>, MemoryAccessError>
pub fn access(self) -> Result<WasmRefAccess<'a, T>, MemoryAccessError>
Gains direct access to the memory of this slice
Trait Implementations§
impl<'a, T: Copy + ValueType> Copy for WasmRef<'a, T>
Auto Trait Implementations§
impl<'a, T> RefUnwindSafe for WasmRef<'a, T>where T: RefUnwindSafe,
impl<'a, T> !Send for WasmRef<'a, T>
impl<'a, T> !Sync for WasmRef<'a, T>
impl<'a, T> Unpin for WasmRef<'a, T>
impl<'a, T> UnwindSafe for WasmRef<'a, T>where T: RefUnwindSafe,
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.
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
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.