pub struct NoExtern { /* private fields */ }
Available on crate feature
runtime
only.Expand description
A reference to the abstract noextern
heap value.
The are no instances of (ref noextern)
: it is an uninhabited type.
There is precisely one instance of (ref null noextern)
, aka nullexternref
:
the null reference.
This NoExtern
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 noextern)
(aka
Option<NoExtern>
) which is always None
.
§Example
let mut config = Config::new();
config.wasm_function_references(true);
config.wasm_gc(true);
let engine = Engine::new(&config)?;
let module = Module::new(
&engine,
r#"
(module
(func (export "f") (param (ref null noextern))
;; If the reference is null, return.
local.get 0
ref.is_null noextern
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 noextern)`-taking function into a typed function that
// takes an `Option<NoExtern>` via the `Func::typed` method.
let f = f.typed::<Option<NoExtern>, ()>(&store)?;
// We can call the typed function, passing the null `noextern` reference.
let result = f.call(&mut store, NoExtern::null());
// The function should not have trapped, because the reference we gave it was
// null (as it had to be, since `NoExtern` is uninhabited).
assert!(result.is_ok());
Implementations§
Trait Implementations§
impl Copy for NoExtern
impl Eq for NoExtern
impl StructuralPartialEq for NoExtern
impl WasmTy for NoExtern
Auto Trait Implementations§
impl Freeze for NoExtern
impl RefUnwindSafe for NoExtern
impl Send for NoExtern
impl Sync for NoExtern
impl Unpin for NoExtern
impl UnwindSafe for NoExtern
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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§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.