1use crate::{
2 bindings::{metacall_destroy, metacall_initialize, metacall_is_initialized},
3 types::MetaCallInitError,
4};
5use std::ptr;
6
7pub struct MetaCallDestroy(unsafe extern "C" fn());
8
9impl Drop for MetaCallDestroy {
10 fn drop(&mut self) {
11 unsafe { self.0() }
12 }
13}
14
15pub fn initialize() -> Result<MetaCallDestroy, MetaCallInitError> {
25 let code = unsafe { metacall_initialize() };
26
27 if code != 0 {
28 return Err(MetaCallInitError::new(code));
29 }
30
31 Ok(MetaCallDestroy(metacall_destroy))
32}
33
34pub fn is_initialized() -> bool {
35 let initialized = unsafe { metacall_is_initialized(ptr::null_mut()) };
36
37 if initialized == 0 {
38 return true;
39 }
40
41 false
42}