pub struct NoFunc { /* private fields */ }
Available on crate feature
runtime
only.Expand description
A reference to the abstract nofunc
heap value.
The are no instances of (ref nofunc)
: it is an uninhabited type.
There is precisely one instance of (ref null nofunc)
, aka nullfuncref
:
the null reference.
This NoFunc
Rust type’s sole purpose is for use with Func::wrap
- and
Func::typed
-style APIs for statically typing a function as taking or
returning a (ref null nofunc)
(aka Option<NoFunc>
) which is always
None
.
§Example
let mut config = Config::new();
config.wasm_function_references(true);
let engine = Engine::new(&config)?;
let module = Module::new(
&engine,
r#"
(module
(func (export "f") (param (ref null nofunc))
;; If the reference is null, return.
local.get 0
ref.is_null nofunc
br_if 0
;; If the reference was not null (which is impossible)
;; then raise a trap.
unreachable
)
)
"#,
)?;
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
let f = instance.get_func(&mut store, "f").unwrap();
// We can cast a `(ref null nofunc)`-taking function into a typed function that
// takes an `Option<NoFunc>` via the `Func::typed` method.
let f = f.typed::<Option<NoFunc>, ()>(&store)?;
// We can call the typed function, passing the null `nofunc` reference.
let result = f.call(&mut store, NoFunc::null());
// The function should not have trapped, because the reference we gave it was
// null (as it had to be, since `NoFunc` is uninhabited).
assert!(result.is_ok());
Implementations§
Trait Implementations§
impl Copy for NoFunc
impl Eq for NoFunc
impl StructuralPartialEq for NoFunc
impl WasmTy for NoFunc
Auto Trait Implementations§
impl Freeze for NoFunc
impl RefUnwindSafe for NoFunc
impl Send for NoFunc
impl Sync for NoFunc
impl Unpin for NoFunc
impl UnwindSafe for NoFunc
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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