Skip to content

Commit c3deca7

Browse files
committed
feat: Make serde serialization and deserialization optional
1 parent c251b76 commit c3deca7

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ edition = "2021"
1515
travis-ci = { repository = "TeXitoi/osmpbfreader-rs" }
1616
appveyor = { repository = "TeXitoi/osmpbfreader-rs" }
1717

18+
[features]
19+
default = ["serde"]
20+
# Enables serde serialization/deserialization for all OpenStreetMap data structures
21+
serde = ["dep:serde", "flat_map/serde1", "smartstring/serde"]
22+
1823
[dependencies]
1924
byteorder = "1.3"
20-
flat_map = { version = "0.0.10", features = ["serde1"] }
25+
flat_map = { version = "0.0.10" }
2126
flate2 = "1.0"
2227
par-map = "0.1"
2328
protobuf = "3"
2429
pub-iterator-type = "0.1"
2530
self_cell = "1.0.2"
26-
serde = { version = "1.0", features = ["derive"] }
27-
smartstring = { version = "1.0.1", features = ["serde"] }
31+
serde = { version = "1.0", features = ["derive"], optional = true }
32+
smartstring = { version = "1.0.1" }
2833

2934
[dev-dependencies]
3035
log = "0.4"

src/objects.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//!
1010
//! There are 3 types of objects: nodes, ways and relations.
1111
12+
#[cfg(feature = "serde")]
1213
use serde::{Deserialize, Serialize};
1314
use smartstring::alias::String;
1415
use std::iter::FromIterator;
@@ -18,7 +19,8 @@ use std::ops::{Deref, DerefMut};
1819
/// [OpenStreetMap wiki page about
1920
/// tags](http://wiki.openstreetmap.org/wiki/Tags) for more
2021
/// information.
21-
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
22+
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
23+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2224
pub struct Tags(::flat_map::FlatMap<String, String>);
2325

2426
impl Tags {
@@ -59,19 +61,23 @@ impl FromIterator<(String, String)> for Tags {
5961
}
6062

6163
/// A node identifier
62-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
64+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
65+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6366
pub struct NodeId(pub i64);
6467

6568
/// A way identifier
66-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
69+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
70+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6771
pub struct WayId(pub i64);
6872

6973
/// A relation identifier
70-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
74+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
75+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7176
pub struct RelationId(pub i64);
7277

7378
/// An OpenStreetMap object identifier
74-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy, Serialize, Deserialize)]
79+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Copy)]
80+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7581
pub enum OsmId {
7682
/// The identifier of a node
7783
Node(NodeId),
@@ -126,7 +132,8 @@ impl OsmId {
126132
}
127133

128134
/// An OpenStreetMap object.
129-
#[derive(Debug, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
135+
#[derive(Debug, PartialEq, PartialOrd, Clone)]
136+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
130137
pub enum OsmObj {
131138
/// A node
132139
Node(Node),
@@ -191,7 +198,8 @@ impl OsmObj {
191198
/// An OpenStreetMap node. See the [OpenStreetMap wiki page about
192199
/// node](http://wiki.openstreetmap.org/wiki/Node) for more
193200
/// information.
194-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
201+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
202+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
195203
pub struct Node {
196204
/// The id of the node.
197205
pub id: NodeId,
@@ -217,7 +225,8 @@ impl Node {
217225
/// An OpenStreetMap way. See the [OpenStreetMap wiki page about
218226
/// way](http://wiki.openstreetmap.org/wiki/Way) for more
219227
/// information.
220-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
228+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
229+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
221230
pub struct Way {
222231
/// The id of the way.
223232
pub id: WayId,
@@ -241,7 +250,8 @@ impl Way {
241250
}
242251

243252
/// A reference to an object with a role. Used in the relation object.
244-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
253+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
254+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
245255
pub struct Ref {
246256
/// Id of the member.
247257
pub member: OsmId,
@@ -252,7 +262,8 @@ pub struct Ref {
252262
/// An OpenStreetMap relation. See the [OpenStreetMap wiki page about
253263
/// relation](http://wiki.openstreetmap.org/wiki/Relation) for more
254264
/// information.
255-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
265+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
266+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
256267
pub struct Relation {
257268
/// The id of the relation.
258269
pub id: RelationId,

0 commit comments

Comments
 (0)