77
88//! Tools for reading a pbf file.
99
10- use crate :: blobs:: { self , result_blob_into_iter } ;
10+ use crate :: blobs;
1111use crate :: error:: { Error , Result } ;
1212use crate :: fileformat:: { Blob , BlobHeader } ;
1313use crate :: objects:: { OsmId , OsmObj } ;
@@ -67,7 +67,7 @@ impl<R: io::Read> OsmPbfReader<R> {
6767 /// }
6868 /// ```
6969 pub fn iter ( & mut self ) -> Iter < R > {
70- Iter ( self . blobs ( ) . flat_map ( result_blob_into_iter) )
70+ Iter ( self . blobs ( ) . flat_map ( blobs :: result_blob_into_iter) )
7171 }
7272
7373 /// Returns a parallel iterator on the OsmObj of the pbf file.
@@ -85,9 +85,53 @@ impl<R: io::Read> OsmPbfReader<R> {
8585 /// }
8686 /// ```
8787 pub fn par_iter ( & mut self ) -> ParIter < ' _ , R > {
88- ParIter ( self . blobs ( ) . par_flat_map ( result_blob_into_iter) )
88+ ParIter ( self . blobs ( ) . par_flat_map ( blobs :: result_blob_into_iter) )
8989 }
9090
91+ /// Returns an iterator on the Node of the pbf file.
92+ pub fn iter_nodes ( & mut self ) -> NodeIter < R > {
93+ NodeIter ( self . blobs ( ) . flat_map ( blobs:: result_blob_into_node_iter) )
94+ }
95+
96+ /// Returns a parallel iterator on the Node of the pbf file.
97+ ///
98+ /// Several threads decode in parallel the file. The memory and
99+ /// CPU usage are guaranteed to be bounded even if the caller stop
100+ /// consuming items.
101+ pub fn par_iter_nodes ( & mut self ) -> NodeParIter < ' _ , R > {
102+ NodeParIter ( self . blobs ( ) . par_flat_map ( blobs:: result_blob_into_node_iter) )
103+ }
104+
105+ /// Returns an iterator on the Way of the pbf file.
106+ pub fn iter_ways ( & mut self ) -> WayIter < R > {
107+ WayIter ( self . blobs ( ) . flat_map ( blobs:: result_blob_into_way_iter) )
108+ }
109+
110+ /// Returns a parallel iterator on the Way of the pbf file.
111+ ///
112+ /// Several threads decode in parallel the file. The memory and
113+ /// CPU usage are guaranteed to be bounded even if the caller stop
114+ /// consuming items.
115+ pub fn par_iter_ways ( & mut self ) -> WayParIter < ' _ , R > {
116+ WayParIter ( self . blobs ( ) . par_flat_map ( blobs:: result_blob_into_way_iter) )
117+ }
118+
119+ /// Returns an iterator on the Relation of the pbf file.
120+ pub fn iter_relations ( & mut self ) -> RelationIter < R > {
121+ RelationIter ( self . blobs ( ) . flat_map ( blobs:: result_blob_into_relation_iter) )
122+ }
123+
124+ /// Returns a parallel iterator on the Relation of the pbf file.
125+ ///
126+ /// Several threads decode in parallel the file. The memory and
127+ /// CPU usage are guaranteed to be bounded even if the caller stop
128+ /// consuming items.
129+ pub fn par_iter_relations ( & mut self ) -> RelationParIter < ' _ , R > {
130+ RelationParIter ( self . blobs ( ) . par_flat_map ( blobs:: result_blob_into_relation_iter) )
131+ }
132+
133+
134+
91135 /// Rewinds the pbf file to the begining.
92136 ///
93137 /// Useful if you want to read several consecutive times the same
@@ -283,14 +327,57 @@ pub fn primitive_block_from_blob(blob: &Blob) -> Result<PrimitiveBlock> {
283327
284328pub_iterator_type ! {
285329 #[ doc="Iterator on the `OsmObj` of the pbf file." ]
286- Iter [ ' a, R ] = iter:: FlatMap <Blobs <' a, R >, blobs:: OsmObjs , fn ( Result <Blob >) -> blobs:: OsmObjs >
330+ Iter [ ' a, R ] = iter:: FlatMap <Blobs <' a, R >, blobs:: OsmObjs <blobs :: OsmBlobObjs > , fn ( Result <Blob >) -> blobs:: OsmObjs <blobs :: OsmBlobObjs > >
287331 where R : io:: Read + ' a
288332}
289333
290334pub_iterator_type ! {
291335 #[ doc="Parallel iterator on the `OsmObj` of the pbf file." ]
292336 ParIter [ ' a, R ] = par_map:: FlatMap <Blobs <' a, R >,
293- blobs:: OsmObjs ,
294- fn ( Result <Blob >) -> blobs:: OsmObjs >
337+ blobs:: OsmObjs <blobs:: OsmBlobObjs >,
338+ fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobObjs >>
339+ where R : io:: Read + ' a
340+ }
341+
342+ pub_iterator_type ! {
343+ #[ doc="Iterator on the `OsmObj` of the pbf file." ]
344+ NodeIter [ ' a, R ] = iter:: FlatMap <Blobs <' a, R >, blobs:: OsmObjs <blobs:: OsmBlobNodes >, fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobNodes >>
345+ where R : io:: Read + ' a
346+ }
347+
348+ pub_iterator_type ! {
349+ #[ doc="Parallel iterator on the `OsmObj` of the pbf file." ]
350+ NodeParIter [ ' a, R ] = par_map:: FlatMap <Blobs <' a, R >,
351+ blobs:: OsmObjs <blobs:: OsmBlobNodes >,
352+ fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobNodes >>
353+ where R : io:: Read + ' a
354+ }
355+
356+ pub_iterator_type ! {
357+ #[ doc="Iterator on the `OsmObj` of the pbf file." ]
358+ WayIter [ ' a, R ] = iter:: FlatMap <Blobs <' a, R >, blobs:: OsmObjs <blobs:: OsmBlobWays >, fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobWays >>
359+ where R : io:: Read + ' a
360+ }
361+
362+ pub_iterator_type ! {
363+ #[ doc="Parallel iterator on the `OsmObj` of the pbf file." ]
364+ WayParIter [ ' a, R ] = par_map:: FlatMap <Blobs <' a, R >,
365+ blobs:: OsmObjs <blobs:: OsmBlobWays >,
366+ fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobWays >>
367+ where R : io:: Read + ' a
368+ }
369+
370+
371+ pub_iterator_type ! {
372+ #[ doc="Iterator on the `OsmObj` of the pbf file." ]
373+ RelationIter [ ' a, R ] = iter:: FlatMap <Blobs <' a, R >, blobs:: OsmObjs <blobs:: OsmBlobRelations >, fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobRelations >>
374+ where R : io:: Read + ' a
375+ }
376+
377+ pub_iterator_type ! {
378+ #[ doc="Parallel iterator on the `OsmObj` of the pbf file." ]
379+ RelationParIter [ ' a, R ] = par_map:: FlatMap <Blobs <' a, R >,
380+ blobs:: OsmObjs <blobs:: OsmBlobRelations >,
381+ fn ( Result <Blob >) -> blobs:: OsmObjs <blobs:: OsmBlobRelations >>
295382 where R : io:: Read + ' a
296383}
0 commit comments