1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use crate::tm_std::*;
use crate::{form::MetaForm, Type, TypeInfo};
#[derive(Clone, Copy)]
pub struct MetaType {
fn_type_info: fn() -> Type<MetaForm>,
type_id: TypeId,
}
impl PartialEq for MetaType {
fn eq(&self, other: &Self) -> bool {
self.type_id == other.type_id
}
}
impl Eq for MetaType {}
impl PartialOrd for MetaType {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.type_id.partial_cmp(&other.type_id)
}
}
impl Ord for MetaType {
fn cmp(&self, other: &Self) -> Ordering {
self.type_id.cmp(&other.type_id)
}
}
impl Hash for MetaType {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
self.type_id.hash(state)
}
}
impl Debug for MetaType {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
self.type_id.fmt(f)
}
}
impl MetaType {
pub fn new<T>() -> Self
where
T: TypeInfo + ?Sized + 'static,
{
Self {
fn_type_info: <T as TypeInfo>::type_info,
type_id: TypeId::of::<T>(),
}
}
pub fn of<T>(_elem: &T) -> Self
where
T: TypeInfo + ?Sized + 'static,
{
Self::new::<T>()
}
pub fn type_info(&self) -> Type<MetaForm> {
(self.fn_type_info)()
}
pub fn type_id(&self) -> TypeId {
self.type_id
}
}