wasmer_c_api/wasm_c_api/
store.rs

1use super::engine::wasm_engine_t;
2use std::cell::UnsafeCell;
3use std::rc::Rc;
4use wasmer_api::{AsStoreMut, AsStoreRef, Store, StoreMut, StoreRef as BaseStoreRef};
5
6#[derive(Clone)]
7pub struct StoreRef {
8    inner: Rc<UnsafeCell<Store>>,
9}
10
11impl StoreRef {
12    pub unsafe fn store(&self) -> BaseStoreRef<'_> {
13        unsafe { (*self.inner.get()).as_store_ref() }
14    }
15
16    pub unsafe fn store_mut(&mut self) -> StoreMut<'_> {
17        unsafe { (*self.inner.get()).as_store_mut() }
18    }
19}
20
21/// Opaque type representing a WebAssembly store.
22#[allow(non_camel_case_types)]
23pub struct wasm_store_t {
24    pub(crate) inner: StoreRef,
25}
26
27/// Creates a new WebAssembly store given a specific [engine][super::engine].
28///
29/// # Example
30///
31/// See the module's documentation.
32#[unsafe(no_mangle)]
33pub unsafe extern "C" fn wasm_store_new(
34    engine: Option<&wasm_engine_t>,
35) -> Option<Box<wasm_store_t>> {
36    let engine = engine?;
37    let store = Store::new(engine.inner.clone());
38
39    Some(Box::new(wasm_store_t {
40        inner: StoreRef {
41            inner: Rc::new(UnsafeCell::new(store)),
42        },
43    }))
44}
45
46/// Deletes a WebAssembly store.
47///
48/// # Example
49///
50/// See the module's documentation.
51#[unsafe(no_mangle)]
52pub unsafe extern "C" fn wasm_store_delete(_store: Option<Box<wasm_store_t>>) {}