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
#[derive(Debug, PartialEq, Clone)]
pub struct ElementMetadata {
pub id: i64,
pub user: String,
pub uid: u64,
pub version: u32,
pub changeset: u64,
pub timestamp: String,
}
#[derive(Debug, PartialEq, Clone)]
pub struct Node {
pub lat: f64,
pub lon: f64,
pub metadata: ElementMetadata,
pub tags: Vec<Tag>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct Way {
pub nodes: Vec<ReferencedNode>,
pub metadata: ElementMetadata,
pub tags: Vec<Tag>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct Relation {
pub members: Vec<RelationMember>,
pub metadata: ElementMetadata,
pub tags: Vec<Tag>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct ReferencedNode {
pub id: i64,
}
#[derive(Debug, PartialEq, Clone)]
pub struct Tag {
pub key: String,
pub value: String
}
#[derive(Debug, PartialEq, Clone)]
pub enum ReferencedElement {
Node(i64),
Way(i64),
Relation(i64)
}
#[derive(Debug, PartialEq, Clone)]
pub struct RelationMember {
pub role: String,
pub element: ReferencedElement,
}
#[derive(Debug, PartialEq, Clone)]
pub enum Element {
Node(Node),
Way(Way),
Relation(Relation),
}
impl Element {
pub fn metadata(&self) -> &ElementMetadata {
match self {
Element::Node(me) => &me.metadata,
Element::Way(me) => &me.metadata,
Element::Relation(me) => &me.metadata,
}
}
}
impl From<Node> for Element {
fn from(node: Node) -> Element {
Element::Node(node)
}
}
impl From<Way> for Element {
fn from(way: Way) -> Element {
Element::Way(way)
}
}
impl From<Relation> for Element {
fn from(relation: Relation) -> Element {
Element::Relation(relation)
}
}