commonlibsse_ng\skse\interfaces/
trampoline.rs

1use std::ffi::c_void;
2
3use crate::skse::{
4    api::{ApiStorageError, get_plugin_handle},
5    impls::stab::SKSETrampolineInterface,
6};
7
8#[derive(Debug, Clone)]
9pub struct TrampolineInterface(&'static SKSETrampolineInterface);
10
11impl TrampolineInterface {
12    /// The version number of the trampoline interface.
13    pub const VERSION: u32 = 1;
14
15    #[inline]
16    pub(crate) const fn new(interface: &'static SKSETrampolineInterface) -> Self {
17        Self(interface)
18    }
19
20    /// Returns the version number of the trampoline interface.
21    #[inline]
22    pub const fn version(&self) -> u32 {
23        self.0.interfaceVersion
24    }
25
26    /// Allocates memory from the branch pool.
27    ///
28    /// # Errors
29    /// If the internal global API storage is uninitialized because forgot to call `skse::init`
30    #[inline]
31    pub fn allocate_from_branch_pool(&self, size: usize) -> Result<*mut c_void, ApiStorageError> {
32        Ok(unsafe { (self.0.AllocateFromBranchPool)(get_plugin_handle()?, size) })
33    }
34
35    /// Allocates memory from the local pool.
36    ///
37    /// # Errors
38    /// If the internal global API storage is uninitialized because forgot to call `skse::init`
39    #[inline]
40    pub fn allocate_from_local_pool(&self, size: usize) -> Result<*mut c_void, ApiStorageError> {
41        Ok(unsafe { (self.0.AllocateFromLocalPool)(get_plugin_handle()?, size) })
42    }
43}