forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtable.rs
More file actions
29 lines (24 loc) · 720 Bytes
/
Copy pathvtable.rs
File metadata and controls
29 lines (24 loc) · 720 Bytes
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
use crate::common::util::FStr;
use fapi_common::vtable::HostVTable;
static mut VTABLE: Option<HostVTable> = None;
/// Intializes the vtable from the given string.
///
/// # Safety
/// This function may not be called from multiple threads
/// at once.
pub fn init_vtable(s: FStr) -> Result<(), serde_json::Error> {
let vtable = serde_json::from_slice(s.into())?;
unsafe {
VTABLE = Some(vtable);
}
Ok(())
}
/// Returns a reference to the host vtable.
///
/// The vtable must have already been initialized.
///
/// # Safety
/// This call must be made _after_ any calls to `init_vtable`.
pub fn vtable() -> &'static HostVTable {
unsafe { VTABLE.as_ref().expect("vtable not initialized") }
}