1use std::{
2 any::{self, TypeId},
3 cmp::Ordering,
4 hash::{Hash, Hasher},
5};
6
7#[derive(Clone, Copy, Debug)]
9pub struct Type {
10 pub name: &'static str,
12 pub id: TypeId,
14}
15
16impl Type {
17 pub(crate) fn new<T: 'static>() -> Type {
18 Type {
19 name: any::type_name::<T>(),
20 id: TypeId::of::<T>(),
21 }
22 }
23}
24
25impl PartialEq for Type {
26 fn eq(&self, other: &Self) -> bool {
27 self.id == other.id
28 }
29}
30
31impl Eq for Type {}
32
33impl PartialOrd for Type {
34 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
35 Some(self.cmp(other))
36 }
37}
38
39impl Ord for Type {
40 fn cmp(&self, other: &Self) -> Ordering {
41 self.id.cmp(&other.id)
42 }
43}
44
45impl Hash for Type {
46 fn hash<H: Hasher>(&self, state: &mut H) {
47 self.id.hash(state);
48 }
49}