浏览代码

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

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

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

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

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

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

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

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

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

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

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