1#[derive(Debug)]
3#[allow(non_camel_case_types)]
4pub enum Type {
5 Ignored,
6 usize(Primitive),
7 isize(Primitive),
8 u8(Primitive),
9 i8(Primitive),
10 u16(Primitive),
11 i16(Primitive),
12 u32(Primitive),
13 i32(Primitive),
14 u64(Primitive),
15 i64(Primitive),
16 f32(Primitive),
17 f64(Primitive),
18 char(Primitive),
19 bool(Primitive),
20 Struct(Struct),
21 Tuple(Tuple),
22 Enum(Enum),
23 Opaque(Opaque),
24}
25
26impl Type {
27 pub fn size(self: &Self) -> Option<usize> {
28 match *self {
29 Type::usize(ref p) => Some(p.size),
30 Type::isize(ref p) => Some(p.size),
31 Type::u8(ref p) => Some(p.size),
32 Type::i8(ref p) => Some(p.size),
33 Type::u16(ref p) => Some(p.size),
34 Type::i16(ref p) => Some(p.size),
35 Type::u32(ref p) => Some(p.size),
36 Type::i32(ref p) => Some(p.size),
37 Type::u64(ref p) => Some(p.size),
38 Type::i64(ref p) => Some(p.size),
39 Type::f32(ref p) => Some(p.size),
40 Type::f64(ref p) => Some(p.size),
41 Type::char(ref p) => Some(p.size),
42 Type::bool(ref p) => Some(p.size),
43 Type::Struct(ref s) => Some(s.size),
44 Type::Tuple(ref t) => Some(t.size),
45 Type::Opaque(ref o) => Some(o.size),
46 Type::Enum(ref o) => Some(o.size),
47 _ => None
48 }
49 }
50 pub fn name(self: &Self) -> Option<&'static str> {
51 match *self {
52 Type::usize(ref p) => Some(p.name),
53 Type::isize(ref p) => Some(p.name),
54 Type::u8(ref p) => Some(p.name),
55 Type::i8(ref p) => Some(p.name),
56 Type::u16(ref p) => Some(p.name),
57 Type::i16(ref p) => Some(p.name),
58 Type::u32(ref p) => Some(p.name),
59 Type::i32(ref p) => Some(p.name),
60 Type::u64(ref p) => Some(p.name),
61 Type::i64(ref p) => Some(p.name),
62 Type::f32(ref p) => Some(p.name),
63 Type::f64(ref p) => Some(p.name),
64 Type::char(ref p) => Some(p.name),
65 Type::bool(ref p) => Some(p.name),
66 Type::Struct(ref s) => Some(s.name),
67 Type::Tuple(ref t) => Some(t.name),
68 Type::Opaque(ref o) => Some(o.name),
69 Type::Enum(ref o) => Some(o.name),
70 _ => None
71 }
72 }
73}
74
75#[derive(Debug)]
77pub enum Visibility {
78 Public,
79 Crate,
80 Restricted,
81 Inherited,
82 Unknown
83}
84
85#[derive(Debug)]
87pub struct Field {
88 pub vis: Visibility,
89 pub offset: usize,
90 pub ty: Type,
91 pub hints: Vec<&'static str>,
92}
93
94#[derive(Debug)]
96pub struct Struct {
97 pub name: &'static str,
98 pub size: usize,
99 pub vis: Visibility,
100 pub fields: Vec<(&'static str, Field)>,
101}
102
103#[derive(Debug)]
105pub struct Tuple {
106 pub name: &'static str,
107 pub size: usize,
108 pub vis: Visibility,
109 pub fields: Vec<Field>,
110}
111
112#[derive(Debug)]
114pub struct Variant {
115 pub fields: Vec<Field>,
116 pub hints: Vec<&'static str>,
117}
118
119#[derive(Debug)]
121pub struct Enum {
122 pub name: &'static str,
123 pub size: usize,
124 pub vis: Visibility,
125 pub variants: Vec<(&'static str, Variant)>,
126}
127
128#[derive(Debug)]
130pub struct Opaque {
131 pub name: &'static str,
132 pub size: usize,
133 pub tys: Vec<Type>,
134}
135
136#[derive(Debug)]
138pub struct Primitive {
139 pub name: &'static str,
140 pub size: usize,
141}