Struct wasmtime::ExternRef

source ·
pub struct ExternRef { /* private fields */ }
Available on crate feature runtime only.
Expand description

Represents an opaque reference to any data within WebAssembly.

Implementations§

source§

impl ExternRef

source

pub fn new<T>(value: T) -> ExternRef
where T: 'static + Any + Send + Sync,

Creates a new instance of ExternRef wrapping the given value.

source

pub fn data(&self) -> &dyn Any

Get the underlying data for this ExternRef.

source

pub fn strong_count(&self) -> usize

Get the strong reference count for this ExternRef.

Note that this loads the reference count with a SeqCst ordering to synchronize with other threads.

source

pub fn ptr_eq(&self, other: &ExternRef) -> bool

Does this ExternRef point to the same inner value as other?

This is only pointer equality, and does not run any inner value’s Eq implementation.

source

pub unsafe fn from_raw(raw: *mut c_void) -> Option<ExternRef>

Creates a new strongly-owned ExternRef from the raw value provided.

This is intended to be used in conjunction with Func::new_unchecked, Func::call_unchecked, and ValRaw with its externref field.

This function assumes that raw is an externref value which is currently rooted within the Store.

§Unsafety

This function is particularly unsafe because raw not only must be a valid externref value produced prior by to_raw but it must also be correctly rooted within the store. When arguments are provided to a callback with Func::new_unchecked, for example, or returned via Func::call_unchecked, if a GC is performed within the store then floating externref values are not rooted and will be GC’d, meaning that this function will no longer be safe to call with the values cleaned up. This function must be invoked before possible GC operations can happen (such as calling wasm).

When in doubt try to not use this. Instead use the safe Rust APIs of TypedFunc and friends.

source

pub unsafe fn to_raw(&self, store: impl AsContextMut) -> *mut c_void

Converts this ExternRef to a raw value suitable to store within a ValRaw.

§Unsafety

Produces a raw value which is only safe to pass into a store if a GC doesn’t happen between when the value is produce and when it’s passed into the store.

Trait Implementations§

source§

impl Clone for ExternRef

source§

fn clone(&self) -> ExternRef

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ExternRef

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ExternRef> for Ref

source§

fn from(e: ExternRef) -> Ref

Converts to this type from the input type.
source§

impl From<ExternRef> for Val

source§

fn from(val: ExternRef) -> Val

Converts to this type from the input type.
source§

impl Pointer for ExternRef

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl WasmTy for ExternRef

Auto Trait Implementations§

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, 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WasmParams for T
where T: WasmTy,

§

type Abi = <(T,) as WasmParams>::Abi

source§

fn typecheck( engine: &Engine, params: impl ExactSizeIterator<Item = ValType>, position: TypeCheckPosition ) -> Result<(), Error>

source§

fn externrefs_count(&self) -> usize

source§

fn into_abi( self, store: &mut StoreOpaque, func_ty: &FuncType ) -> Result<<T as WasmParams>::Abi, Error>

source§

unsafe fn invoke<R>( func: NonNull<VMNativeCallFunction>, vmctx1: *mut VMOpaqueContext, vmctx2: *mut VMContext, abi: <T as WasmParams>::Abi ) -> <R as WasmResults>::ResultAbi
where R: WasmResults,

source§

impl<T> WasmResults for T
where T: WasmTy, (<T as WasmTy>::Abi,): HostAbi,

§

type ResultAbi = <(T,) as WasmResults>::ResultAbi

source§

unsafe fn from_abi( store: &mut StoreOpaque, abi: <T as WasmResults>::ResultAbi ) -> T

source§

impl<T> WasmRet for T
where T: WasmTy,

§

type Abi = <T as WasmTy>::Abi

§

type Retptr = ()

§

type Fallible = Result<T, Error>

source§

fn compatible_with_store(&self, store: &StoreOpaque) -> bool

source§

unsafe fn into_abi_for_ret( self, store: &mut StoreOpaque, _retptr: () ) -> Result<<T as WasmRet>::Abi, Error>

source§

fn func_type(engine: &Engine, params: impl Iterator<Item = ValType>) -> FuncType

source§

unsafe fn wrap_trampoline( ptr: *mut ValRaw, f: impl FnOnce(<T as WasmRet>::Retptr) -> <T as WasmRet>::Abi )

source§

fn into_fallible(self) -> Result<T, Error>

source§

fn fallible_from_error(error: Error) -> Result<T, Error>