use chrono::NaiveDateTime;
use fnv::FnvHashMap as HashMap;
use kstring::KString;
use rust_decimal::Decimal;
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Element {
Node(Node),
Way(Way),
Relation(Relation),
}
impl Element {
pub fn id(&self) -> Id {
match self {
Element::Node(Node { id, .. })
| Element::Way(Way { id, .. })
| Element::Relation(Relation { id, .. }) => *id,
}
}
pub fn tags(&self) -> &HashMap<KString, KString> {
match self {
Element::Node(Node { tags, .. })
| Element::Way(Way { tags, .. })
| Element::Relation(Relation { tags, .. }) => tags,
}
}
pub fn info(&self) -> Option<&Info> {
match self {
Element::Node(Node { info, .. })
| Element::Way(Way { info, .. })
| Element::Relation(Relation { info, .. }) => info.as_ref(),
}
}
pub fn strip_info(&mut self) {
let info = match self {
Element::Node(Node { info, .. })
| Element::Way(Way { info, .. })
| Element::Relation(Relation { info, .. }) => info,
};
*info = None;
}
pub fn as_node(&self) -> Option<&Node> {
if let Element::Node(n) = self {
Some(n)
} else {
None
}
}
pub fn as_way(&self) -> Option<&Way> {
if let Element::Way(w) = self {
Some(w)
} else {
None
}
}
pub fn as_relation(&self) -> Option<&Relation> {
if let Element::Relation(r) = self {
Some(r)
} else {
None
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Id(pub i64);
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Node {
pub id: Id,
pub tags: HashMap<KString, KString>,
pub info: Option<Info>,
pub lat: Decimal,
pub lon: Decimal,
}
impl Node {
pub fn strip_info(&mut self) {
self.info = None;
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Way {
pub id: Id,
pub tags: HashMap<KString, KString>,
pub info: Option<Info>,
pub refs: Vec<Id>,
}
impl Way {
pub fn strip_info(&mut self) {
self.info = None;
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Relation {
pub id: Id,
pub tags: HashMap<KString, KString>,
pub info: Option<Info>,
pub members: Vec<Member>,
}
impl Relation {
pub fn strip_info(&mut self) {
self.info = None;
}
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Member {
pub id: Id,
pub ty: MemberType,
pub role: Option<KString>,
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MemberType {
Node,
Way,
Relation,
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Info {
pub version: i32,
pub timestamp: Option<NaiveDateTime>,
pub changeset: Option<i64>,
pub uid: Option<i32>,
pub user: Option<KString>,
pub visible: Option<bool>,
}