wiggle::wasmtime_crate

Enum Ref

pub enum Ref {
    Func(Option<Func>),
    Extern(Option<Rooted<ExternRef>>),
    Any(Option<Rooted<AnyRef>>),
}
Expand description

A reference.

References come in three broad flavors:

  1. Function references. These are references to a function that can be invoked.

  2. External references. These are references to data that is external and opaque to the Wasm guest, provided by the host.

  3. Internal references. These are references to allocations inside the Wasm’s heap, such as structs and arrays. These are part of the GC proposal, and not yet implemented in Wasmtime.

At the Wasm level, there are nullable and non-nullable variants of each type of reference. Both variants are represented with Ref at the Wasmtime API level. For example, values of both (ref extern) and (ref null extern) types will be represented as Ref::Extern(Option<ExternRef>) in the Wasmtime API. Nullable references are represented as Option<Ref> where null references are represented as None. Wasm can construct null references via the ref.null <heap-type> instruction.

References are non-forgable: Wasm cannot create invalid references, for example, by claiming that the integer 0xbad1bad2 is actually a reference.

Variants§

§

Func(Option<Func>)

A first-class reference to a WebAssembly function.

The host, or the Wasm guest, can invoke this function.

The host can create function references via Func::new or Func::wrap.

The Wasm guest can create non-null function references via the ref.func instruction, or null references via the ref.null func instruction.

§

Extern(Option<Rooted<ExternRef>>)

A reference to an value outside of the Wasm heap.

These references are opaque to the Wasm itself. Wasm can’t create non-null external references, nor do anything with them accept pass them around as function arguments and returns and place them into globals and tables.

Wasm can create null external references via the ref.null extern instruction.

§

Any(Option<Rooted<AnyRef>>)

An internal reference.

The AnyRef type represents WebAssembly anyref values. These can be references to structs and arrays or inline/unboxed 31-bit integers.

Unlike externref, Wasm guests can directly allocate anyrefs, and does not need to rely on the host to do that.

Implementations§

§

impl Ref

pub fn null(heap_type: &HeapType) -> Ref

Create a null reference to the given heap type.

pub fn is_null(&self) -> bool

Is this a null reference?

pub fn is_non_null(&self) -> bool

Is this a non-null reference?

pub fn is_extern(&self) -> bool

Is this an extern reference?

pub fn as_extern(&self) -> Option<Option<&Rooted<ExternRef>>>

Get the underlying extern reference, if any.

Returns None if this Ref is not an extern reference, eg it is a func reference.

Returns Some(None) if this Ref is a null extern reference.

Returns Some(Some(_)) if this Ref is a non-null extern reference.

pub fn unwrap_extern(&self) -> Option<&Rooted<ExternRef>>

Get the underlying extern reference, panicking if this is a different kind of reference.

Returns None if this Ref is a null extern reference.

Returns Some(_) if this Ref is a non-null extern reference.

pub fn is_any(&self) -> bool

Is this an any reference?

pub fn as_any(&self) -> Option<Option<&Rooted<AnyRef>>>

Get the underlying any reference, if any.

Returns None if this Ref is not an any reference, eg it is a func reference.

Returns Some(None) if this Ref is a null any reference.

Returns Some(Some(_)) if this Ref is a non-null any reference.

pub fn unwrap_any(&self) -> Option<&Rooted<AnyRef>>

Get the underlying any reference, panicking if this is a different kind of reference.

Returns None if this Ref is a null any reference.

Returns Some(_) if this Ref is a non-null any reference.

pub fn is_func(&self) -> bool

Is this a func reference?

pub fn as_func(&self) -> Option<Option<&Func>>

Get the underlying func reference, if any.

Returns None if this Ref is not an func reference, eg it is an extern reference.

Returns Some(None) if this Ref is a null func reference.

Returns Some(Some(_)) if this Ref is a non-null func reference.

pub fn unwrap_func(&self) -> Option<&Func>

Get the underlying func reference, panicking if this is a different kind of reference.

Returns None if this Ref is a null func reference.

Returns Some(_) if this Ref is a non-null func reference.

pub fn ty(&self, store: impl AsContext) -> Result<RefType, Error>

Get the type of this reference.

§Errors

Return an error if this reference has been unrooted.

§Panics

Panics if this reference is associated with a different store.

pub fn matches_ty( &self, store: impl AsContext, ty: &RefType, ) -> Result<bool, Error>

Does this reference value match the given type?

Returns an error if the underlying Rooted has been unrooted.

§Panics

Panics if this reference is not associated with the given store.

Trait Implementations§

§

impl Clone for Ref

§

fn clone(&self) -> Ref

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
§

impl Debug for Ref

§

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

Formats the value using the given formatter. Read more
§

impl From<Func> for Ref

§

fn from(f: Func) -> Ref

Converts to this type from the input type.
§

impl From<Option<Func>> for Ref

§

fn from(f: Option<Func>) -> Ref

Converts to this type from the input type.
§

impl From<Option<Rooted<AnyRef>>> for Ref

§

fn from(e: Option<Rooted<AnyRef>>) -> Ref

Converts to this type from the input type.
§

impl From<Option<Rooted<ArrayRef>>> for Ref

§

fn from(e: Option<Rooted<ArrayRef>>) -> Ref

Converts to this type from the input type.
§

impl From<Option<Rooted<ExternRef>>> for Ref

§

fn from(e: Option<Rooted<ExternRef>>) -> Ref

Converts to this type from the input type.
§

impl From<Option<Rooted<StructRef>>> for Ref

§

fn from(e: Option<Rooted<StructRef>>) -> Ref

Converts to this type from the input type.
§

impl From<Ref> for Val

§

fn from(val: Ref) -> Val

Converts to this type from the input type.
§

impl From<Rooted<AnyRef>> for Ref

§

fn from(e: Rooted<AnyRef>) -> Ref

Converts to this type from the input type.
§

impl From<Rooted<ArrayRef>> for Ref

§

fn from(e: Rooted<ArrayRef>) -> Ref

Converts to this type from the input type.
§

impl From<Rooted<ExternRef>> for Ref

§

fn from(e: Rooted<ExternRef>) -> Ref

Converts to this type from the input type.
§

impl From<Rooted<StructRef>> for Ref

§

fn from(e: Rooted<StructRef>) -> Ref

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Ref

§

impl RefUnwindSafe for Ref

§

impl Send for Ref

§

impl Sync for Ref

§

impl Unpin for Ref

§

impl UnwindSafe for Ref

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more