substrate_wasmtime/
ref.rs

1#![allow(missing_docs)]
2
3use std::any::Any;
4use wasmtime_runtime::VMExternRef;
5
6/// Represents an opaque reference to any data within WebAssembly.
7#[derive(Clone, Debug)]
8pub struct ExternRef {
9    pub(crate) inner: VMExternRef,
10}
11
12impl ExternRef {
13    /// Creates a new instance of `ExternRef` wrapping the given value.
14    pub fn new<T>(value: T) -> ExternRef
15    where
16        T: 'static + Any,
17    {
18        let inner = VMExternRef::new(value);
19        ExternRef { inner }
20    }
21
22    /// Get the underlying data for this `ExternRef`.
23    pub fn data(&self) -> &dyn Any {
24        &*self.inner
25    }
26
27    /// Get the strong reference count for this `ExternRef`.
28    pub fn strong_count(&self) -> usize {
29        self.inner.strong_count()
30    }
31
32    /// Does this `ExternRef` point to the same inner value as `other`?0
33    ///
34    /// This is *only* pointer equality, and does *not* run any inner value's
35    /// `Eq` implementation.
36    pub fn ptr_eq(&self, other: &ExternRef) -> bool {
37        VMExternRef::eq(&self.inner, &other.inner)
38    }
39}