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
use std::ops::Index;
use super::super::syn::Field as SynField;
use super::super::Ty as Ty;
type SynFields = Vec<SynField>;
#[derive(Clone,Debug)]
pub struct Field {
pub id: Option<String>,
pub ty: Ty
}
impl Field {
pub fn from_syn_field(x: &SynField) -> Field {
Field {
id: match &x.ident {
&Option::None => None,
&Option::Some(ref x) => Some(x.to_string())
},
ty: x.ty.clone()
}
}
pub fn get_name<'a>(&'a self) -> Option<&'a str> {
match &self.id {
&Option::Some(ref s) => Some(s),
_ => None
}
}
}
#[derive(Clone,Debug)]
pub struct Fields(pub Vec<Field>);
impl From<SynFields> for Fields {
fn from(x: SynFields) -> Fields {
let mut v = Vec::with_capacity(x.len());
for item in x {
v.push(Field::from_syn_field(&item));
}
Fields(v)
}
}
impl<'a> From<&'a SynFields> for Fields {
fn from(x: &'a SynFields) -> Fields {
let mut v = Vec::with_capacity(x.len());
for item in x {
v.push(Field::from_syn_field(&item));
}
Fields(v)
}
}
impl Index<usize> for Fields {
type Output = Field;
#[inline(always)]
fn index(&self, x: usize) -> &Self::Output {
self.0.index(x)
}
}
impl Fields {
#[inline(always)]
pub fn len(&self) -> usize {
self.0.len()
}
pub fn get_id(&self, x: usize) -> String {
match self[x].id {
Option::Some(ref i) => i.to_string(),
Option::None => x.to_string()
}
}
#[inline(always)]
pub fn get_ty<'a>(&'a self, x: usize) -> &'a Ty {
&self[x].ty
}
}