use core::any::TypeId;
use core::fmt::Debug;
use core::hash::Hash;
#[derive(Copy, Clone)]
pub struct TypeInfo {
name: &'static str,
id: TypeId,
}
impl TypeInfo {
pub fn of<T: ?Sized + 'static>() -> Self {
TypeInfo {
name: core::any::type_name::<T>(),
id: TypeId::of::<T>(),
}
}
#[inline]
pub fn name(&self) -> &'static str {
self.name
}
#[inline]
pub fn id(&self) -> TypeId {
self.id
}
}
impl Hash for TypeInfo {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
impl PartialEq for TypeInfo {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Eq for TypeInfo {}
impl Debug for TypeInfo {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.name)
}
}