99
1010use std:: iter;
1111
12- use crate :: blocks:: { self , OsmObjs as OsmBlockObjs , Relations as BlockRelations , Ways as BlockWays , Nodes as BlockNodes } ;
12+ use crate :: blocks:: {
13+ self , Nodes as BlockNodes , OsmObjs as OsmBlockObjs , Relations as BlockRelations ,
14+ Ways as BlockWays ,
15+ } ;
1316use crate :: fileformat:: Blob ;
1417use crate :: objects:: OsmObj ;
1518use crate :: osmformat:: PrimitiveBlock ;
1619
1720macro_rules! wrap {
1821 ( $name: ident, $wrap_type: ident => $inner_type: path) => {
19- self_cell:: self_cell!(
20- #[ allow( missing_docs) ]
21- pub struct $name {
22- owner: PrimitiveBlock ,
23-
24- #[ covariant]
25- dependent: $wrap_type,
26- }
27- ) ;
28-
29- impl Iterator for $name {
30- type Item = $inner_type;
31-
32- fn next( & mut self ) -> Option <Self :: Item > {
33- self . with_dependent_mut( |_, objs| objs. next( ) )
34- }
35- }
36-
22+ self_cell:: self_cell!(
23+ #[ allow( missing_docs) ]
24+ pub struct $name {
25+ owner: PrimitiveBlock ,
26+
27+ #[ covariant]
28+ dependent: $wrap_type,
29+ }
30+ ) ;
31+
32+ impl Iterator for $name {
33+ type Item = $inner_type;
34+
35+ fn next( & mut self ) -> Option <Self :: Item > {
36+ self . with_dependent_mut( |_, objs| objs. next( ) )
37+ }
38+ }
3739 } ;
3840}
3941
@@ -45,6 +47,7 @@ wrap!(OsmBlobNodes, BlockNodes => super::Node);
4547/// An iterator on `Result<OsmObj>`.
4648pub struct OsmObjs < T : Iterator > ( OsmObjsImpl < T > ) ;
4749
50+ #[ allow( clippy:: type_complexity) ]
4851enum OsmObjsImpl < T : Iterator > {
4952 OkIter ( iter:: Map < T , fn ( <T as Iterator >:: Item ) -> crate :: Result < <T as Iterator >:: Item > > ) ,
5053 ErrIter ( iter:: Once < crate :: Result < <T as Iterator >:: Item > > ) ,
@@ -63,31 +66,39 @@ impl<T: Iterator> Iterator for OsmObjs<T> {
6366/// Transforms a `Result<blob>` into a `Iterator<Item = Result<OsmObj>>`.
6467pub fn result_blob_into_iter ( result : crate :: Result < Blob > ) -> OsmObjs < OsmBlobObjs > {
6568 match result. and_then ( |b| crate :: reader:: primitive_block_from_blob ( & b) ) {
66- Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter ( OsmBlobObjs :: new ( block, blocks:: iter) . map ( Ok ) ) ) ,
69+ Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter (
70+ OsmBlobObjs :: new ( block, blocks:: iter) . map ( Ok ) ,
71+ ) ) ,
6772 Err ( e) => OsmObjs ( OsmObjsImpl :: ErrIter ( iter:: once ( Err ( e) ) ) ) ,
6873 }
6974}
7075
7176/// Transforms a `Result<blob>` into a `Iterator<Item = Result<Node>>`.
7277pub fn result_blob_into_node_iter ( result : crate :: Result < Blob > ) -> OsmObjs < OsmBlobNodes > {
7378 match result. and_then ( |b| crate :: reader:: primitive_block_from_blob ( & b) ) {
74- Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter ( OsmBlobNodes :: new ( block, blocks:: nodes) . map ( Ok ) ) ) ,
79+ Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter (
80+ OsmBlobNodes :: new ( block, blocks:: nodes) . map ( Ok ) ,
81+ ) ) ,
7582 Err ( e) => OsmObjs ( OsmObjsImpl :: ErrIter ( iter:: once ( Err ( e) ) ) ) ,
7683 }
7784}
7885
7986/// Transforms a `Result<blob>` into a `Iterator<Item = Result<Way>>`.
8087pub fn result_blob_into_way_iter ( result : crate :: Result < Blob > ) -> OsmObjs < OsmBlobWays > {
8188 match result. and_then ( |b| crate :: reader:: primitive_block_from_blob ( & b) ) {
82- Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter ( OsmBlobWays :: new ( block, blocks:: ways) . map ( Ok ) ) ) ,
89+ Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter (
90+ OsmBlobWays :: new ( block, blocks:: ways) . map ( Ok ) ,
91+ ) ) ,
8392 Err ( e) => OsmObjs ( OsmObjsImpl :: ErrIter ( iter:: once ( Err ( e) ) ) ) ,
8493 }
8594}
8695
8796/// Transforms a `Result<blob>` into a `Iterator<Item = Result<Relation>>`.
8897pub fn result_blob_into_relation_iter ( result : crate :: Result < Blob > ) -> OsmObjs < OsmBlobRelations > {
8998 match result. and_then ( |b| crate :: reader:: primitive_block_from_blob ( & b) ) {
90- Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter ( OsmBlobRelations :: new ( block, blocks:: relations) . map ( Ok ) ) ) ,
99+ Ok ( block) => OsmObjs ( OsmObjsImpl :: OkIter (
100+ OsmBlobRelations :: new ( block, blocks:: relations) . map ( Ok ) ,
101+ ) ) ,
91102 Err ( e) => OsmObjs ( OsmObjsImpl :: ErrIter ( iter:: once ( Err ( e) ) ) ) ,
92103 }
93104}
0 commit comments