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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use std::fmt;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone)]
pub enum FieldIdent {
Index(usize),
Name(String)
}
impl FieldIdent {
pub fn to_string(&self) -> String {
match *self {
FieldIdent::Index(i) => format!("Field {}", i),
FieldIdent::Name(ref s) => s.clone(),
}
}
}
impl fmt::Display for FieldIdent {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", self.to_string())
}
}
impl PartialEq for FieldIdent {
fn eq(&self, other: &FieldIdent) -> bool {
self.to_string().eq(&other.to_string())
}
}
impl Eq for FieldIdent {}
impl Hash for FieldIdent {
fn hash<H>(&self, state: &mut H) where H: Hasher {
self.to_string().hash(state)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub enum FieldType {
Unsigned,
Signed,
Text,
Boolean,
Float
}
#[derive(Debug, Clone)]
pub struct TypedFieldIdent {
pub ident: FieldIdent,
pub ty: FieldType
}
impl TypedFieldIdent {
pub fn new(ident: FieldIdent, ty: FieldType) -> TypedFieldIdent {
TypedFieldIdent {
ident: ident,
ty: ty
}
}
}
#[derive(Debug, Clone)]
pub struct SrcField {
pub ty_ident: TypedFieldIdent,
pub src_index: usize,
}
impl SrcField {
pub fn new(ident: FieldIdent, ty: FieldType, src_index: usize) -> SrcField {
SrcField {
ty_ident: TypedFieldIdent::new(ident, ty),
src_index: src_index
}
}
pub fn from_ty_ident(ty_ident: TypedFieldIdent, src_index: usize) -> SrcField {
SrcField {
ty_ident: ty_ident,
src_index: src_index
}
}
}
#[derive(Debug, Clone)]
pub struct DsField {
pub ty_ident: TypedFieldIdent,
pub ds_index: usize,
}
impl DsField {
pub fn new(ident: FieldIdent, ty: FieldType, ds_index: usize) -> DsField {
DsField {
ty_ident: TypedFieldIdent::new(ident, ty),
ds_index: ds_index,
}
}
pub fn from_src(src: &SrcField, ds_index: usize) -> DsField {
DsField {
ty_ident: src.ty_ident.clone(),
ds_index: ds_index
}
}
}
#[macro_export]
macro_rules! fields {
($($name:expr => $ty:expr),*) => {{
use $crate::field::TypedFieldIdent;
vec![$(
TypedFieldIdent::new(
FieldIdent::Name($name.to_string()),
$ty
)
),*]
}}
}