osmpbf/
lib.rs

1/*!
2A fast reader for the OpenStreetMap PBF file format (\*.osm.pbf).
3
4## Usage
5
6Add this to your `Cargo.toml`:
7
8```toml
9[dependencies]
10osmpbf = "0.2"
11```
12
13## Example: Count ways
14
15Here's a simple example that counts all the OpenStreetMap way elements in a
16file:
17
18```rust
19use osmpbf::{ElementReader, Element};
20
21let reader = ElementReader::from_path("tests/test.osm.pbf")?;
22let mut ways = 0_u64;
23
24// Increment the counter by one for each way.
25reader.for_each(|element| {
26    if let Element::Way(_) = element {
27        ways += 1;
28    }
29})?;
30
31println!("Number of ways: {ways}");
32# assert_eq!(ways, 1);
33# Ok::<(), std::io::Error>(())
34```
35
36## Example: Count ways in parallel
37
38In this second example, we also count the ways but make use of all cores by
39decoding the file in parallel:
40
41```rust
42use osmpbf::{ElementReader, Element};
43
44let reader = ElementReader::from_path("tests/test.osm.pbf")?;
45
46// Count the ways
47let ways = reader.par_map_reduce(
48    |element| {
49        match element {
50            Element::Way(_) => 1,
51            _ => 0,
52        }
53    },
54    || 0_u64,      // Zero is the identity value for addition
55    |a, b| a + b   // Sum the partial results
56)?;
57
58println!("Number of ways: {ways}");
59# assert_eq!(ways, 1);
60# Ok::<(), std::io::Error>(())
61```
62*/
63
64#![recursion_limit = "1024"]
65
66#[cfg(any(
67    all(feature = "rust-zlib", feature = "zlib"),
68    all(feature = "rust-zlib", feature = "zlib-ng"),
69    all(feature = "zlib", feature = "zlib-ng")
70))]
71std::compile_error!(
72    "Multiple zlib features are enabled. Make sure to only activate one zlib feature,\n\
73    for example by using these cargo flags: --no-default-features --features zlib-ng"
74);
75
76pub use blob::*;
77pub use block::*;
78pub use dense::*;
79pub use elements::*;
80pub use error::{BlobError, Error, ErrorKind, Result};
81pub use indexed::*;
82pub use mmap_blob::*;
83pub use reader::*;
84
85pub mod blob;
86pub mod block;
87pub mod dense;
88pub mod elements;
89mod error;
90pub mod indexed;
91pub mod mmap_blob;
92pub mod reader;
93
94mod proto {
95    include!(concat!(env!("OUT_DIR"), "/mod.rs"));
96}