Skip to content

Commit f83f96f

Browse files
authored
feat: Make serde serialization and deserialization optional via serde feature (#52)
1 parent 1941664 commit f83f96f

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

.github/workflows/sanity_checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ jobs:
2424

2525
- name: Run tests
2626
run: cargo test
27+
28+
- name: Run tests with optional features
29+
run: cargo test --all-features

Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "osmpbfreader"
3-
version = "0.18.0"
3+
version = "0.19.0"
44
authors = ["Guillaume Pinot <[email protected]>"]
55
description = "Read OpenStreetMap PBF files in rust."
66
documentation = "https://docs.rs/osmpbfreader"
@@ -11,16 +11,20 @@ license = "WTFPL"
1111
readme = "README.md"
1212
edition = "2021"
1313

14+
[features]
15+
# Enables serde serialization/deserialization for all OpenStreetMap data structures
16+
serde = ["dep:serde", "flat_map/serde1", "smartstring/serde"]
17+
1418
[dependencies]
1519
byteorder = "1.3"
16-
flat_map = { version = "0.0.10", features = ["serde1"] }
20+
flat_map = "0.0.10"
1721
flate2 = "1.0"
1822
par-map = "0.1"
1923
protobuf = "3"
2024
pub-iterator-type = "0.1"
2125
self_cell = "1.0.2"
22-
serde = { version = "1.0", features = ["derive"] }
23-
smartstring = { version = "1.0.1", features = ["serde"] }
26+
serde = { version = "1.0", features = ["derive"], optional = true }
27+
smartstring = "1.0.1"
2428

2529
[dev-dependencies]
2630
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)