1use chrono::NaiveDateTime;
2use fnv::FnvHashMap as HashMap;
3use kstring::KString;
4use rust_decimal::Decimal;
5
6#[derive(Debug, PartialEq, Eq, Clone)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub enum Element {
12 Node(Node),
13 Way(Way),
14 Relation(Relation),
15}
16
17impl Element {
18 pub fn id(&self) -> Id {
19 match self {
20 Element::Node(Node { id, .. })
21 | Element::Way(Way { id, .. })
22 | Element::Relation(Relation { id, .. }) => *id,
23 }
24 }
25
26 pub fn tags(&self) -> &HashMap<KString, KString> {
27 match self {
28 Element::Node(Node { tags, .. })
29 | Element::Way(Way { tags, .. })
30 | Element::Relation(Relation { tags, .. }) => tags,
31 }
32 }
33
34 pub fn info(&self) -> Option<&Info> {
35 match self {
36 Element::Node(Node { info, .. })
37 | Element::Way(Way { info, .. })
38 | Element::Relation(Relation { info, .. }) => info.as_ref(),
39 }
40 }
41
42 pub fn strip_info(&mut self) {
44 let info = match self {
45 Element::Node(Node { info, .. })
46 | Element::Way(Way { info, .. })
47 | Element::Relation(Relation { info, .. }) => info,
48 };
49 *info = None;
50 }
51
52 pub fn as_node(&self) -> Option<&Node> {
53 if let Element::Node(n) = self {
54 Some(n)
55 } else {
56 None
57 }
58 }
59
60 pub fn as_way(&self) -> Option<&Way> {
61 if let Element::Way(w) = self {
62 Some(w)
63 } else {
64 None
65 }
66 }
67
68 pub fn as_relation(&self) -> Option<&Relation> {
69 if let Element::Relation(r) = self {
70 Some(r)
71 } else {
72 None
73 }
74 }
75}
76
77#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub struct Id(pub i64);
81
82#[derive(Debug, PartialEq, Eq, Clone)]
86#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
87pub struct Node {
88 pub id: Id,
89 pub tags: HashMap<KString, KString>,
90 pub info: Option<Info>,
91 pub lat: Decimal,
93 pub lon: Decimal,
95}
96
97impl Node {
98 pub fn strip_info(&mut self) {
100 self.info = None;
101 }
102}
103
104#[derive(Debug, PartialEq, Eq, Clone)]
108#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109pub struct Way {
110 pub id: Id,
111 pub tags: HashMap<KString, KString>,
112 pub info: Option<Info>,
113
114 pub refs: Vec<Id>,
119}
120
121impl Way {
122 pub fn strip_info(&mut self) {
124 self.info = None;
125 }
126}
127
128#[derive(Debug, PartialEq, Eq, Clone)]
133#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
134pub struct Relation {
135 pub id: Id,
136 pub tags: HashMap<KString, KString>,
137 pub info: Option<Info>,
138 pub members: Vec<Member>,
142}
143
144impl Relation {
145 pub fn strip_info(&mut self) {
147 self.info = None;
148 }
149}
150
151#[derive(Debug, PartialEq, Eq, Clone, Hash)]
153#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
154pub struct Member {
155 pub id: Id,
156 pub ty: MemberType,
157 pub role: Option<KString>,
161}
162
163#[derive(Debug, PartialEq, Eq, Clone, Hash)]
165#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
166pub enum MemberType {
167 Node,
168 Way,
169 Relation,
170}
171
172#[derive(Debug, PartialEq, Eq, Clone, Hash)]
176#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
177pub struct Info {
178 pub version: i32,
182 pub timestamp: Option<NaiveDateTime>,
184 pub changeset: Option<i64>,
188 pub uid: Option<i32>,
190 pub user: Option<KString>,
194 pub visible: Option<bool>,
199}