1use std::{any::TypeId, hash::Hash};
2
3#[derive(Clone, Copy)]
4pub struct TypeInfo {
5 pub type_id: TypeId,
6 pub type_name: &'static str,
7}
8
9impl TypeInfo {
10 pub fn new<T: 'static>(type_name: &'static str) -> Self {
11 Self {
12 type_id: TypeId::of::<T>(),
13 type_name,
14 }
15 }
16}
17
18impl std::fmt::Display for TypeInfo {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 write!(f, "{}", self.type_name)
21 }
22}
23
24impl std::fmt::Debug for TypeInfo {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 let type_id = self.type_id;
27 write!(f, "TypeId({self}, {type_id:?})")
28 }
29}
30
31impl PartialEq for TypeInfo {
32 fn eq(&self, other: &Self) -> bool {
33 self.type_id == other.type_id
34 }
35}
36
37impl Eq for TypeInfo {}
38
39impl Hash for TypeInfo {
40 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
41 self.type_id.hash(state);
42 }
43}