Struct wasmtime::ExternRef

source ·
#[repr(transparent)]
pub struct ExternRef { /* private fields */ }
Expand description

Represents an opaque reference to any data within WebAssembly.

Implementations§

source§

impl ExternRef

source

pub fn new<T>(value: T) -> ExternRefwhere 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: usize) -> 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) -> usize

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 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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 = mem::align_of::<T>()

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V