Skip to content

Commit

Permalink
Add serde serialization to objects (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-de authored and TeXitoi committed Mar 1, 2018
1 parent f62eec6 commit f882da3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ appveyor = { repository = "TeXitoi/osmpbfreader-rs" }
flate2 = "0.2.17"
byteorder = "1.0"
protobuf = "1.1"
flat_map = "0.0.4"
flat_map = { version = "0.0.7", features = ["serde1"] }
rental = "0.4"
par-map = "0.1"
pub-iterator-type = "0.1"
serde = "1.0"
serde_derive = "1.0"

[dev-dependencies]
log = "0.3.6"
env_logger = "0.3"
env_logger = "0.3"
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ extern crate rental;
extern crate par_map;
#[macro_use]
extern crate pub_iterator_type;
extern crate serde;
#[macro_use]
extern crate serde_derive;

pub use objects::*;
pub use error::Error;
Expand Down
20 changes: 10 additions & 10 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::iter::FromIterator;
/// [OpenStreetMap wiki page about
/// tags](http://wiki.openstreetmap.org/wiki/Tags) for more
/// information.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Tags(TagsImpl);
/// FlatMap representing the key-value pairs of the tags
pub type TagsImpl = ::flat_map::FlatMap<String, String>;
Expand Down Expand Up @@ -48,19 +48,19 @@ impl FromIterator<(String, String)> for Tags {
}

/// A node identifier
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
pub struct NodeId(pub i64);

/// A way identifier
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
pub struct WayId(pub i64);

/// A relation identifier
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
pub struct RelationId(pub i64);

/// An OpenStreetMap object identifier
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
pub enum OsmId {
/// The identifier of a node
Node(NodeId),
Expand Down Expand Up @@ -106,7 +106,7 @@ impl OsmId {
}

/// An OpenStreetMap object.
#[derive(Debug, PartialEq, PartialOrd, Clone)]
#[derive(Debug, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
pub enum OsmObj {
/// A node
Node(Node),
Expand Down Expand Up @@ -170,7 +170,7 @@ impl OsmObj {
/// An OpenStreetMap node. See the [OpenStreetMap wiki page about
/// node](http://wiki.openstreetmap.org/wiki/Node) for more
/// information.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
pub struct Node {
/// The id of the node.
pub id: NodeId,
Expand All @@ -195,7 +195,7 @@ impl Node {
/// An OpenStreetMap way. See the [OpenStreetMap wiki page about
/// way](http://wiki.openstreetmap.org/wiki/Way) for more
/// information.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
pub struct Way {
/// The id of the way.
pub id: WayId,
Expand All @@ -218,7 +218,7 @@ impl Way {
}

/// A reference to an object with a role. Used in the relation object.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
pub struct Ref {
/// Id of the member.
pub member: OsmId,
Expand All @@ -229,7 +229,7 @@ pub struct Ref {
/// An OpenStreetMap relation. See the [OpenStreetMap wiki page about
/// relation](http://wiki.openstreetmap.org/wiki/Relation) for more
/// information.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
pub struct Relation {
/// The id of the relation.
pub id: RelationId,
Expand Down

0 comments on commit f882da3

Please sign in to comment.