#[cfg(test)]
#[path = "../tests/entities/factory.rs"]
mod tests;
use crate::NotThreadSafe;
use crate::interfaces::ServerTools;
use sdk_raw::vcall;
use std::ffi::CStr;
use std::marker::PhantomData;
use std::ptr::NonNull;
#[doc(alias("IEntityFactory"))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct EntityFactory<'s> {
raw: NonNull<sys::IEntityFactory>,
_scope: PhantomData<&'s ()>,
_not_thread_safe: NotThreadSafe,
}
impl EntityFactory<'_> {
pub const fn as_ptr(self) -> *mut sys::IEntityFactory {
self.raw.as_ptr()
}
}
impl<'s> ServerTools<'s> {
#[doc(alias("GetEntityFactoryDictionary", "FindFactory"))]
pub fn entity_factory(self, class_name: &CStr) -> Option<EntityFactory<'s>> {
let dictionary = NonNull::new(unsafe {
vcall!(self.as_ptr() => IServerTools_GetEntityFactoryDictionary())
})?;
let factory = unsafe {
vcall!(dictionary.as_ptr() => IEntityFactoryDictionary_FindFactory(class_name.as_ptr()))
};
NonNull::new(factory).map(|raw| EntityFactory {
raw,
_scope: PhantomData,
_not_thread_safe: PhantomData,
})
}
}