[−][src]Struct holochain_wasmer_host::prelude::WasmPtr
A zero-cost type that represents a pointer to something in Wasm linear memory.
This type can be used directly in the host function arguments:
pub fn host_import(ctx: &mut Ctx, ptr: WasmPtr<u32>) { let memory = ctx.memory(0); let derefed_ptr = ptr.deref(memory).expect("pointer in bounds"); let inner_val: u32 = derefed_ptr.get(); println!("Got {} from Wasm memory address 0x{:X}", inner_val, ptr.offset()); // update the value being pointed to derefed_ptr.set(inner_val + 1); }
Implementations
impl<T, Ty> WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
Methods relevant to all types of WasmPtr
.
pub fn new(offset: u32) -> WasmPtr<T, Ty>
[src]
Create a new WasmPtr
at the given offset.
pub fn offset(self) -> u32
[src]
Get the offset into Wasm linear memory for this WasmPtr
.
impl<T> WasmPtr<T, Item> where
T: ValueType + Copy,
[src]
T: ValueType + Copy,
Methods for WasmPtr
s to data that can be dereferenced, namely to types
that implement [ValueType
], meaning that they're valid for all possible
bit patterns.
pub fn deref(self, memory: &'a Memory) -> Option<&'a Cell<T>>
[src]
Dereference the WasmPtr
getting access to a &Cell<T>
allowing for
reading and mutating of the inner value.
This method is unsound if used with unsynchronized shared memory. If you're unsure what that means, it likely does not apply to you. This invariant will be enforced in the future.
pub unsafe fn deref_mut(self, memory: &'a Memory) -> Option<&'a mut Cell<T>>
[src]
Mutably dereference this WasmPtr
getting a &mut Cell<T>
allowing for
direct access to a &mut T
.
Safety
- This method does not do any aliasing checks: it's possible to create
&mut T
that point to the same memory. You should ensure that you have exclusive access to Wasm linear memory before calling this method.
impl<T> WasmPtr<T, Array> where
T: ValueType + Copy,
[src]
T: ValueType + Copy,
Methods for WasmPtr
s to arrays of data that can be dereferenced, namely to
types that implement [ValueType
], meaning that they're valid for all
possible bit patterns.
pub fn deref(
self,
memory: &Memory,
index: u32,
length: u32
) -> Option<&[Cell<T>]>
[src]
self,
memory: &Memory,
index: u32,
length: u32
) -> Option<&[Cell<T>]>
Dereference the WasmPtr
getting access to a &[Cell<T>]
allowing for
reading and mutating of the inner values.
This method is unsound if used with unsynchronized shared memory. If you're unsure what that means, it likely does not apply to you. This invariant will be enforced in the future.
pub unsafe fn deref_mut(
self,
memory: &Memory,
index: u32,
length: u32
) -> Option<&mut [Cell<T>]>
[src]
self,
memory: &Memory,
index: u32,
length: u32
) -> Option<&mut [Cell<T>]>
Mutably dereference this WasmPtr
getting a &mut [Cell<T>]
allowing for
direct access to a &mut [T]
.
Safety
- This method does not do any aliasing checks: it's possible to create
&mut T
that point to the same memory. You should ensure that you have exclusive access to Wasm linear memory before calling this method.
pub fn get_utf8_string(self, memory: &Memory, str_len: u32) -> Option<&str>
[src]
Get a UTF-8 string from the WasmPtr
with the given length.
Note that this method returns a reference to Wasm linear memory. The
underlying data can be mutated if the Wasm is allowed to execute or
an aliasing WasmPtr
is used to mutate memory.
pub fn get_utf8_string_with_nul(self, memory: &Memory) -> Option<&str>
[src]
Get a UTF-8 string from the WasmPtr
, where the string is nul-terminated.
Note that this does not account for UTF-8 strings that contain nul themselves,
[get_utf8_string
] has to be used for those.
Also note that this method returns a reference to Wasm linear memory. The
underlying data can be mutated if the Wasm is allowed to execute or
an aliasing WasmPtr
is used to mutate memory.
Trait Implementations
impl<T, Ty> Clone for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
impl<T, Ty> Copy for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
impl<T, Ty> Debug for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
impl<T, Ty> Eq for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
impl<T, Ty> PartialEq<WasmPtr<T, Ty>> for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
fn eq(&self, other: &WasmPtr<T, Ty>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, Ty> ValueType for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
impl<T, Ty> WasmExternType for WasmPtr<T, Ty> where
T: Copy,
[src]
T: Copy,
type Native = i32
Native wasm type for this WasmExternType
.
fn to_native(self) -> <WasmPtr<T, Ty> as WasmExternType>::Native
[src]
fn from_native(n: <WasmPtr<T, Ty> as WasmExternType>::Native) -> WasmPtr<T, Ty>
[src]
Auto Trait Implementations
impl<T, Ty> RefUnwindSafe for WasmPtr<T, Ty> where
T: RefUnwindSafe,
Ty: RefUnwindSafe,
T: RefUnwindSafe,
Ty: RefUnwindSafe,
impl<T, Ty> Send for WasmPtr<T, Ty> where
T: Send,
Ty: Send,
T: Send,
Ty: Send,
impl<T, Ty> Sync for WasmPtr<T, Ty> where
T: Sync,
Ty: Sync,
T: Sync,
Ty: Sync,
impl<T, Ty> Unpin for WasmPtr<T, Ty> where
T: Unpin,
Ty: Unpin,
T: Unpin,
Ty: Unpin,
impl<T, Ty> UnwindSafe for WasmPtr<T, Ty> where
T: UnwindSafe,
Ty: UnwindSafe,
T: UnwindSafe,
Ty: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<Rets> TrapEarly<Rets> for Rets where
Rets: WasmTypeList,
[src]
Rets: WasmTypeList,
type Error = Infallible
The error type for this trait.
fn report(self) -> Result<Rets, Infallible>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<A> WasmTypeList for A where
A: WasmExternType,
[src]
A: WasmExternType,
type CStruct = S1<A>
CStruct type.
type RetArray = [u64; 1]
Array of return values.
fn from_ret_array(array: <A as WasmTypeList>::RetArray) -> A
[src]
fn empty_ret_array() -> <A as WasmTypeList>::RetArray
[src]
fn from_c_struct(c_struct: <A as WasmTypeList>::CStruct) -> A
[src]
fn into_c_struct(self) -> <A as WasmTypeList>::CStruct
[src]
fn types() -> &'static [Type]
[src]
unsafe fn call<Rets>(
self,
f: NonNull<Func>,
wasm: Wasm,
ctx: *mut Ctx
) -> Result<Rets, RuntimeError> where
Rets: WasmTypeList,
[src]
self,
f: NonNull<Func>,
wasm: Wasm,
ctx: *mut Ctx
) -> Result<Rets, RuntimeError> where
Rets: WasmTypeList,