瀏覽代碼

Derive Clone, Debug for public types

Johannes Hofmann 8 年之前
父節點
當前提交
944c178cd5
共有 6 個文件被更改,包括 28 次插入2 次删除
  1. 4
    1
      src/blob.rs
  2. 7
    0
      src/block.rs
  3. 3
    0
      src/dense.rs
  4. 9
    0
      src/elements.rs
  5. 3
    1
      src/mmap_blob.rs
  6. 2
    0
      src/reader.rs

+ 4
- 1
src/blob.rs 查看文件

@@ -27,7 +27,7 @@ pub static MAX_BLOB_MESSAGE_SIZE: u64 = 32 * 1024 * 1024;
27 27
 
28 28
 
29 29
 /// The content type of a blob.
30
-#[derive(Debug, Eq, PartialEq)]
30
+#[derive(Clone, Debug, Eq, PartialEq)]
31 31
 pub enum BlobType<'a> {
32 32
     /// Blob contains a `HeaderBlock`.
33 33
     OsmHeader,
@@ -40,6 +40,7 @@ pub enum BlobType<'a> {
40 40
 
41 41
 //TODO rename variants to fit proto files
42 42
 /// The decoded content of a blob (analogous to `BlobType`).
43
+#[derive(Clone, Debug)]
43 44
 pub enum BlobDecode<'a> {
44 45
     /// Blob contains a `HeaderBlock`.
45 46
     OsmHeader(Box<HeaderBlock>),
@@ -54,6 +55,7 @@ pub enum BlobDecode<'a> {
54 55
 ///
55 56
 /// A PBF file consists of a sequence of blobs. This type supports decoding the content of a blob
56 57
 /// to different types of blocks that are usually more interesting to the user.
58
+#[derive(Clone, Debug)]
57 59
 pub struct Blob {
58 60
     header: fileformat::BlobHeader,
59 61
     blob: fileformat::Blob,
@@ -111,6 +113,7 @@ impl Blob {
111 113
 }
112 114
 
113 115
 /// A reader for PBF files that allows iterating over `Blob`s.
116
+#[derive(Clone, Debug)]
114 117
 pub struct BlobReader<R: Read> {
115 118
     reader: R,
116 119
     last_blob_ok: bool,

+ 7
- 0
src/block.rs 查看文件

@@ -8,6 +8,7 @@ use std;
8 8
 
9 9
 
10 10
 /// A `HeaderBlock`. It contains metadata about following `PrimitiveBlock`s.
11
+#[derive(Clone, Debug)]
11 12
 pub struct HeaderBlock {
12 13
     header: osmformat::HeaderBlock,
13 14
 }
@@ -30,6 +31,7 @@ impl HeaderBlock {
30 31
 }
31 32
 
32 33
 /// A `PrimitiveBlock`. It contains a sequence of groups.
34
+#[derive(Clone, Debug)]
33 35
 pub struct PrimitiveBlock {
34 36
     block: osmformat::PrimitiveBlock,
35 37
 }
@@ -46,6 +48,7 @@ impl PrimitiveBlock {
46 48
 }
47 49
 
48 50
 /// A `PrimitiveGroup` contains a sequence of elements of one type.
51
+#[derive(Clone, Debug)]
49 52
 pub struct PrimitiveGroup<'a> {
50 53
     block: &'a osmformat::PrimitiveBlock,
51 54
     group: &'a osmformat::PrimitiveGroup,
@@ -83,6 +86,7 @@ impl<'a> PrimitiveGroup<'a> {
83 86
 }
84 87
 
85 88
 /// An iterator over the groups in a `PrimitiveBlock`.
89
+#[derive(Clone, Debug)]
86 90
 pub struct GroupIter<'a> {
87 91
     block: &'a osmformat::PrimitiveBlock,
88 92
     groups: std::slice::Iter<'a, osmformat::PrimitiveGroup>,
@@ -115,6 +119,7 @@ impl<'a> Iterator for GroupIter<'a> {
115 119
 impl<'a> ExactSizeIterator for GroupIter<'a> {}
116 120
 
117 121
 /// An iterator over the nodes in a `PrimitiveGroup`.
122
+#[derive(Clone, Debug)]
118 123
 pub struct GroupNodeIter<'a> {
119 124
     block: &'a osmformat::PrimitiveBlock,
120 125
     nodes: std::slice::Iter<'a, osmformat::Node>,
@@ -149,6 +154,7 @@ impl<'a> Iterator for GroupNodeIter<'a> {
149 154
 impl<'a> ExactSizeIterator for GroupNodeIter<'a> {}
150 155
 
151 156
 /// An iterator over the ways in a `PrimitiveGroup`.
157
+#[derive(Clone, Debug)]
152 158
 pub struct GroupWayIter<'a> {
153 159
     block: &'a osmformat::PrimitiveBlock,
154 160
     ways: std::slice::Iter<'a, osmformat::Way>,
@@ -183,6 +189,7 @@ impl<'a> Iterator for GroupWayIter<'a> {
183 189
 impl<'a> ExactSizeIterator for GroupWayIter<'a> {}
184 190
 
185 191
 /// An iterator over the relations in a `PrimitiveGroup`.
192
+#[derive(Clone, Debug)]
186 193
 pub struct GroupRelationIter<'a> {
187 194
     block: &'a osmformat::PrimitiveBlock,
188 195
     rels: std::slice::Iter<'a, osmformat::Relation>,

+ 3
- 0
src/dense.rs 查看文件

@@ -8,6 +8,7 @@ use std;
8 8
 
9 9
 //TODO Add getter functions for id, version, uid, ...
10 10
 /// An OpenStreetMap node element from a compressed array of dense nodes (See [OSM wiki](http://wiki.openstreetmap.org/wiki/Node)).
11
+#[derive(Clone, Debug)]
11 12
 pub struct DenseNode<'a> {
12 13
     block: &'a osmformat::PrimitiveBlock,
13 14
 
@@ -62,6 +63,7 @@ impl<'a> DenseNode<'a> {
62 63
 }
63 64
 
64 65
 /// An iterator over dense nodes. It decodes the delta encoded values.
66
+#[derive(Clone, Debug)]
65 67
 pub struct DenseNodeIter<'a> {
66 68
     block: &'a osmformat::PrimitiveBlock,
67 69
     dids: std::slice::Iter<'a, i64>, // deltas
@@ -177,6 +179,7 @@ impl<'a> Iterator for DenseNodeIter<'a> {
177 179
 impl<'a> ExactSizeIterator for DenseNodeIter<'a> {}
178 180
 
179 181
 /// An iterator over the tags in a dense node.
182
+#[derive(Clone, Debug)]
180 183
 pub struct DenseTagIter<'a> {
181 184
     block: &'a osmformat::PrimitiveBlock,
182 185
     keys_vals_indices: std::slice::Iter<'a, i32>,

+ 9
- 0
src/elements.rs 查看文件

@@ -8,6 +8,7 @@ use std;
8 8
 
9 9
 
10 10
 /// An OpenStreetMap node element (See [OSM wiki](http://wiki.openstreetmap.org/wiki/Node)).
11
+#[derive(Clone, Debug)]
11 12
 pub struct Node<'a> {
12 13
     block: &'a PrimitiveBlock,
13 14
     osmnode: &'a osmformat::Node,
@@ -60,6 +61,7 @@ impl<'a> Node<'a> {
60 61
 ///
61 62
 /// A way contains an ordered list of node references that can be accessed with the `refs` or the
62 63
 /// `refs_slice` method.
64
+#[derive(Clone, Debug)]
63 65
 pub struct Way<'a> {
64 66
     block: &'a PrimitiveBlock,
65 67
     osmway: &'a osmformat::Way,
@@ -110,6 +112,7 @@ impl<'a> Way<'a> {
110 112
 /// An OpenStreetMap relation element (See [OSM wiki](http://wiki.openstreetmap.org/wiki/Relation)).
111 113
 ///
112 114
 /// A relation contains an ordered list of members that can be of any element type.
115
+#[derive(Clone, Debug)]
113 116
 pub struct Relation<'a> {
114 117
     block: &'a PrimitiveBlock,
115 118
     osmrel: &'a osmformat::Relation,
@@ -151,6 +154,7 @@ impl<'a> Relation<'a> {
151 154
 /// An iterator over the references of a way.
152 155
 ///
153 156
 /// Each reference corresponds to a node id.
157
+#[derive(Clone, Debug)]
154 158
 pub struct WayRefIter<'a> {
155 159
     deltas: std::slice::Iter<'a, i64>,
156 160
     current: i64,
@@ -177,6 +181,7 @@ impl<'a> Iterator for WayRefIter<'a> {
177 181
 impl<'a> ExactSizeIterator for WayRefIter<'a> {}
178 182
 
179 183
 /// The element type of a relation member.
184
+#[derive(Clone, Debug, Eq, PartialEq)]
180 185
 pub enum RelMemberType {
181 186
     Node,
182 187
     Way,
@@ -197,6 +202,7 @@ impl From<osmformat::Relation_MemberType> for RelMemberType {
197 202
 /// A member of a relation.
198 203
 ///
199 204
 /// Each member has a member type and a member id that references an element of that type.
205
+#[derive(Clone, Debug)]
200 206
 pub struct RelMember<'a> {
201 207
     block: &'a PrimitiveBlock,
202 208
     pub role_sid: i32,
@@ -212,6 +218,7 @@ impl<'a> RelMember<'a> {
212 218
 }
213 219
 
214 220
 /// An iterator over the members of a relation.
221
+#[derive(Clone, Debug)]
215 222
 pub struct RelMemberIter<'a> {
216 223
     block: &'a PrimitiveBlock,
217 224
     role_sids: std::slice::Iter<'a, i32>,
@@ -260,6 +267,7 @@ impl<'a> Iterator for RelMemberIter<'a> {
260 267
 impl<'a> ExactSizeIterator for RelMemberIter<'a> {}
261 268
 
262 269
 /// An iterator over the tags of an element.
270
+#[derive(Clone, Debug)]
263 271
 pub struct TagIter<'a> {
264 272
     block: &'a PrimitiveBlock,
265 273
     key_indices: std::slice::Iter<'a, u32>,
@@ -293,6 +301,7 @@ impl<'a> Iterator for TagIter<'a> {
293 301
 impl<'a> ExactSizeIterator for TagIter<'a> {}
294 302
 
295 303
 /// Additional metadata that might be included in each element.
304
+#[derive(Clone, Debug)]
296 305
 pub struct Info<'a> {
297 306
     block: &'a PrimitiveBlock,
298 307
     info: &'a osmformat::Info,

+ 3
- 1
src/mmap_blob.rs 查看文件

@@ -16,6 +16,7 @@ use util::parse_message_from_bytes;
16 16
 
17 17
 
18 18
 /// A read-only memory map.
19
+#[derive(Debug)]
19 20
 pub struct Mmap {
20 21
     mmap: memmap::Mmap,
21 22
 }
@@ -78,6 +79,7 @@ impl Mmap {
78 79
 }
79 80
 
80 81
 /// A PBF blob from a memory map.
82
+#[derive(Clone, Debug)]
81 83
 pub struct MmapBlob<'a> {
82 84
     header: BlobHeader,
83 85
     data: &'a [u8],
@@ -113,7 +115,7 @@ impl<'a> MmapBlob<'a> {
113 115
 }
114 116
 
115 117
 /// A reader for memory mapped PBF files that allows iterating over `MmapBlob`s.
116
-#[derive(Clone)]
118
+#[derive(Clone, Debug)]
117 119
 pub struct MmapBlobReader<'a> {
118 120
     mmap: &'a Mmap,
119 121
     offset: usize,

+ 2
- 0
src/reader.rs 查看文件

@@ -11,6 +11,7 @@ use std::path::Path;
11 11
 
12 12
 
13 13
 /// A reader for PBF files that gives access to the stored elements: nodes, ways and relations.
14
+#[derive(Clone, Debug)]
14 15
 pub struct ElementReader<R: Read> {
15 16
     blob_iter: BlobReader<R>,
16 17
 }
@@ -198,6 +199,7 @@ impl ElementReader<BufReader<File>> {
198 199
 }
199 200
 
200 201
 /// An enum with the OSM core elements: nodes, ways and relations.
202
+#[derive(Clone, Debug)]
201 203
 pub enum Element<'a> {
202 204
     /// A node. Also, see `DenseNode`.
203 205
     Node(Node<'a>),