1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2014-2015 Guillaume Pinot <texitoi(a)texitoi.eu>
//
// This work is free. You can redistribute it and/or modify it under
// the terms of the Do What The Fuck You Want To Public License,
// Version 2, as published by Sam Hocevar. See the COPYING file for
// more details.

//! Iterators of OpenStreetMap objects from a block.

use groups;
use objects::{Node, OsmObj, Relation, Way};
use osmformat::PrimitiveBlock;

pub_iterator_type! {
    #[doc="Iterator on the `OsmObj` of a `PrimitiveBlock`."]
    OsmObjs['a] = Box<dyn Iterator<Item = OsmObj> + 'a>
}

pub fn iter(block: &PrimitiveBlock) -> OsmObjs {
    let f = move |g| groups::iter(g, block);
    OsmObjs(Box::new(block.get_primitivegroup().iter().flat_map(f)))
}

pub_iterator_type! {
    #[doc="Iterator on the `Node` of a `PrimitiveBlock`."]
    Nodes['a] = Box<dyn Iterator<Item = Node> + 'a>
}

pub fn nodes(block: &PrimitiveBlock) -> Nodes {
    let f = move |g| groups::nodes(g, block);
    Nodes(Box::new(block.get_primitivegroup().iter().flat_map(f)))
}

pub_iterator_type! {
    #[doc="Iterator on the `Way` of a `PrimitiveBlock`."]
    Ways['a] = Box<dyn Iterator<Item = Way> + 'a>
}

pub fn ways(block: &PrimitiveBlock) -> Ways {
    let f = move |g| groups::ways(g, block);
    Ways(Box::new(block.get_primitivegroup().iter().flat_map(f)))
}

pub_iterator_type! {
    #[doc="Iterator on the `Relation` of a `PrimitiveBlock`."]
    Relations['a] = Box<dyn Iterator<Item = Relation> + 'a>
}

pub fn relations(block: &PrimitiveBlock) -> Relations {
    let f = move |g| groups::relations(g, block);
    Relations(Box::new(block.get_primitivegroup().iter().flat_map(f)))
}