1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! The dummy `ExternRef` type used when the `gc` cargo feature is disabled.
//!
//! Providing a dummy type means that downstream users need to do fewer
//! `#[cfg(...)]`s versus if this type or its methods simply didn't exist. The
//! only methods that are left missing are constructors.

#![allow(missing_docs)]

use crate::runtime::Uninhabited;
use crate::AsContextMut;
use std::any::Any;
use std::ffi::c_void;
use wasmtime_runtime::VMExternRef;

/// Represents an opaque reference to any data within WebAssembly.
///
/// Due to compilation configuration, this is an uninhabited type: enable the
/// `gc` cargo feature to properly use this type.
#[derive(Clone, Debug)]
pub struct ExternRef {
    _inner: Uninhabited,
}

impl ExternRef {
    pub(crate) fn from_vm_extern_ref(inner: VMExternRef) -> Self {
        inner.assert_unreachable()
    }

    pub(crate) fn into_vm_extern_ref(self) -> VMExternRef {
        match self._inner {}
    }

    pub fn data(&self) -> &dyn Any {
        match self._inner {}
    }

    pub fn strong_count(&self) -> usize {
        match self._inner {}
    }

    pub fn ptr_eq(&self, _other: &ExternRef) -> bool {
        match self._inner {}
    }

    pub unsafe fn from_raw(raw: *mut c_void) -> Option<ExternRef> {
        assert!(raw.is_null());
        None
    }

    pub unsafe fn to_raw(&self, mut store: impl AsContextMut) -> *mut c_void {
        let _ = &mut store;
        match self._inner {}
    }
}

impl std::fmt::Pointer for ExternRef {
    fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self._inner {}
    }
}