emf_core_base_rs/
init.rs

1use crate::ffi::{
2    sys::api::GetFunctionFn as GetFunctionFnFFI, CBase as CBaseFFI, CBaseInterface, CBaseLoader,
3};
4use crate::{CBase, CBaseAccess, CBaseRef};
5use std::ptr::NonNull;
6
7/// Trait for loading the interface.
8pub trait CBaseAPILoader<'interface> {
9    /// Type of the interface.
10    type Interface: CBaseAccess<'interface>;
11
12    /// Fetches the `emf-core-base` interface.
13    ///
14    /// # Safety
15    ///
16    /// The parameter `get_function_fn` must be able to accept `base_module`.
17    ///
18    /// # Panics
19    ///
20    /// This function panics if it can not fetch the interface.
21    unsafe fn fetch_interface(
22        base_module: Option<NonNull<CBaseFFI>>,
23        get_function_fn: GetFunctionFnFFI,
24    ) -> Self::Interface;
25}
26
27impl<'interface> CBaseAPILoader<'interface> for CBase<'interface> {
28    type Interface = Self;
29
30    unsafe fn fetch_interface(
31        base_module: Option<NonNull<CBaseFFI>>,
32        get_function_fn: GetFunctionFnFFI,
33    ) -> Self::Interface {
34        Self::new(CBaseRef::new(CBaseInterface::fetch_interface(
35            base_module,
36            get_function_fn,
37        )))
38    }
39}