use std::any::{type_name, TypeId};
use crate::logical::Registered;
use crate::logical::Registry;
use crate::raw::registry_id::RegistryId;
use crate::TypeInfo;
#[derive(Copy, Clone)]
pub struct RegistryEntry {
registry_id: RegistryId,
get_type_info: fn() -> &'static dyn TypeInfo,
get_type_id: fn() -> TypeId,
get_type_name: fn() -> &'static str
}
impl RegistryEntry {
pub const fn new<
R: Registry + ?Sized,
T: Registered<R> + ?Sized
>() -> Self {
Self {
registry_id: RegistryId::of::<R>(),
get_type_info: || <T as Registered<R>>::type_info(),
get_type_id: TypeId::of::<T>,
get_type_name: type_name::<T>
}
}
pub const fn registry_id(&self) -> RegistryId {
self.registry_id
}
pub fn type_info(&self) -> &'static dyn TypeInfo {
(self.get_type_info)()
}
pub fn type_id(&self) -> TypeId {
(self.get_type_id)()
}
pub fn type_name(&self) -> &'static str {
(self.get_type_name)()
}
}