1use core::any::{Any, TypeId};
6
7fn type_of<U, V>() -> bool
9where
10    U: core::any::Any + ?Sized,
11    V: core::any::Any + ?Sized,
12{
13    core::any::TypeId::of::<U>() == core::any::TypeId::of::<V>()
14}
15
16pub trait IsType: 'static {
17    fn of<T: 'static>() -> bool {
18        type_of::<Self, T>()
19    }
20
21    fn is<T: 'static>(&self) -> bool {
22        type_of::<Self, T>()
23    }
24}
25
26pub trait DType: Any {
28    fn type_id(&self) -> TypeId {
29        Any::type_id(self)
30    }
31
32    fn type_name(&self) -> &'static str {
33        core::any::type_name::<Self>()
34    }
35}
36
37pub trait DTypeExt: DType {
38    fn of<T: 'static>() -> bool {
39        type_of::<Self, T>()
40    }
41
42    fn is<T: 'static>(&self) -> bool {
43        type_of::<Self, T>()
44    }
45
46    fn type_id(&self) -> TypeId {
47        Any::type_id(self)
48    }
49
50    fn type_name<T>() -> &'static str
51    where
52        T: ?Sized,
53    {
54        core::any::type_name::<T>()
55    }
56}
57
58impl<T: 'static> IsType for T {}
62
63impl dyn DType {}