pub struct NoneRef { /* private fields */ }
Available on crate feature
runtime
only.Expand description
A reference to the abstract none
heap value.
The are no instances of (ref none)
: it is an uninhabited type.
There is precisely one instance of (ref null none)
, aka nullref
: the
null reference.
This NoneRef
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 none)
(aka Option<NoneRef>
)
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 none))
;; If the reference is null, return.
local.get 0
ref.is_null none
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 none)`-taking function into a typed function that
// takes an `Option<NoneRef>` via the `Func::typed` method.
let f = f.typed::<Option<NoneRef>, ()>(&store)?;
// We can call the typed function, passing the null `none` reference.
let result = f.call(&mut store, NoneRef::null());
// The function should not have trapped, because the reference we gave it was
// null (as it had to be, since `NoneRef` is uninhabited).
assert!(result.is_ok());
Implementations§
Trait Implementations§
impl Copy for NoneRef
impl Eq for NoneRef
impl StructuralPartialEq for NoneRef
impl WasmTy for NoneRef
Auto Trait Implementations§
impl Freeze for NoneRef
impl RefUnwindSafe for NoneRef
impl Send for NoneRef
impl Sync for NoneRef
impl Unpin for NoneRef
impl UnwindSafe for NoneRef
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.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