use crate::{
HeapType, Ref, RefType, Result, Val, ValRaw, ValType, WasmTy,
store::{AutoAssertNoGc, StoreOpaque},
};
use core::convert::Infallible;
use core::mem::MaybeUninit;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct NoneRef {
_inner: Infallible,
}
impl NoneRef {
#[inline]
pub fn null() -> Option<Self> {
None
}
#[inline]
pub fn null_ref() -> Ref {
Ref::Extern(None)
}
#[inline]
pub fn null_val() -> Val {
Val::ExternRef(None)
}
}
unsafe impl WasmTy for NoneRef {
#[inline]
fn valtype() -> ValType {
ValType::Ref(RefType::new(false, HeapType::None))
}
#[inline]
fn compatible_with_store(&self, _store: &StoreOpaque) -> bool {
match self._inner {}
}
#[inline]
fn dynamic_concrete_type_check(&self, _: &StoreOpaque, _: bool, _: &HeapType) -> Result<()> {
match self._inner {}
}
#[inline]
fn is_vmgcref_and_points_to_object(&self) -> bool {
match self._inner {}
}
fn store(self, _store: &mut AutoAssertNoGc<'_>, _ptr: &mut MaybeUninit<ValRaw>) -> Result<()> {
match self._inner {}
}
unsafe fn load(_store: &mut AutoAssertNoGc<'_>, _ptr: &ValRaw) -> Self {
unreachable!("NoneRef is uninhabited")
}
}
unsafe impl WasmTy for Option<NoneRef> {
#[inline]
fn valtype() -> ValType {
ValType::Ref(RefType::new(true, HeapType::None))
}
#[inline]
fn compatible_with_store(&self, _store: &StoreOpaque) -> bool {
true
}
#[inline]
fn dynamic_concrete_type_check(
&self,
_store: &StoreOpaque,
_nullable: bool,
_ty: &HeapType,
) -> Result<()> {
unreachable!()
}
#[inline]
fn store(self, _store: &mut AutoAssertNoGc<'_>, ptr: &mut MaybeUninit<ValRaw>) -> Result<()> {
ptr.write(ValRaw::externref(0));
Ok(())
}
#[inline]
unsafe fn load(_store: &mut AutoAssertNoGc<'_>, ptr: &ValRaw) -> Self {
debug_assert_eq!(ptr.get_externref(), 0);
None
}
}