7 次程式碼提交

作者 SHA1 備註 提交日期
  Johannes Hofmann c3ec6341f1 Release 0.1.17 5 年之前
  Johannes Hofmann db47f0d699 README: Add Rust 2015 notice 5 年之前
  Johannes Hofmann 6f290a6041 Run cargo fmt 5 年之前
  Johannes Hofmann ab8cf2044c CI: Fail compilation on warning 5 年之前
  Johannes Hofmann 9bba9b6ab5 indexed: Fix clippy warning 5 年之前
  Johannes Hofmann 3e1524056f Stop using Error::description method 5 年之前
  Johannes Hofmann 92e91b5767 CI: Remove deprecated keyword `sudo` 5 年之前
共有 8 個檔案被更改,包括 57 行新增35 行删除
  1. 2
    1
      .travis.yml
  2. 1
    1
      Cargo.toml
  3. 1
    1
      README.md
  4. 2
    2
      examples/indexed.rs
  5. 1
    4
      src/blob.rs
  6. 26
    3
      src/error.rs
  7. 7
    8
      src/indexed.rs
  8. 17
    15
      tests/read.rs

+ 2
- 1
.travis.yml 查看文件

@@ -1,5 +1,4 @@
1 1
 dist: trusty
2
-sudo: false
3 2
 language: rust
4 3
 rust:
5 4
   - stable
@@ -11,3 +10,5 @@ script:
11 10
       cargo test --verbose;
12 11
       cargo test --verbose --no-default-features;
13 12
       cargo doc --verbose;
13
+env:
14
+  - RUSTFLAGS="-D warnings"

+ 1
- 1
Cargo.toml 查看文件

@@ -1,6 +1,6 @@
1 1
 [package]
2 2
 name = "osmpbf"
3
-version = "0.1.16"
3
+version = "0.1.17"
4 4
 authors = ["Johannes Hofmann <mail@b-r-u.org>"]
5 5
 readme = "README.md"
6 6
 repository = "https://github.com/b-r-u/osmpbf"

+ 1
- 1
README.md 查看文件

@@ -19,7 +19,7 @@ Add this to your `Cargo.toml`:
19 19
 osmpbf = "0.1"
20 20
 ```
21 21
 
22
-and this to your crate root:
22
+and if you're using Rust 2015, add this line to the crate root:
23 23
 
24 24
 ```rust
25 25
 extern crate osmpbf;

+ 2
- 2
examples/indexed.rs 查看文件

@@ -3,7 +3,7 @@
3 3
 
4 4
 extern crate osmpbf;
5 5
 
6
-use osmpbf::{IndexedReader, Element};
6
+use osmpbf::{Element, IndexedReader};
7 7
 use std::error::Error;
8 8
 
9 9
 fn main() -> Result<(), Box<dyn Error>> {
@@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
28 28
                 Element::Way(_way) => ways += 1,
29 29
                 Element::Node(_node) => nodes += 1,
30 30
                 Element::DenseNode(_dense_node) => nodes += 1,
31
-                Element::Relation(_) => {}, // should not occur
31
+                Element::Relation(_) => {} // should not occur
32 32
             }
33 33
         },
34 34
     )?;

+ 1
- 4
src/blob.rs 查看文件

@@ -149,7 +149,6 @@ impl BlobHeader {
149 149
     }
150 150
 }
151 151
 
152
-
153 152
 /// A reader for PBF files that allows iterating over `Blob`s.
154 153
 #[derive(Clone, Debug)]
155 154
 pub struct BlobReader<R: Read + Send> {
@@ -222,9 +221,7 @@ impl<R: Read + Send> BlobReader<R> {
222 221
                 }
223 222
             };
224 223
 
225
-        self.offset = self
226
-            .offset
227
-            .map(|x| ByteOffset(x.0 + header_size));
224
+        self.offset = self.offset.map(|x| ByteOffset(x.0 + header_size));
228 225
 
229 226
         Some(Ok(header))
230 227
     }

+ 26
- 3
src/error.rs 查看文件

@@ -105,9 +105,32 @@ impl From<Error> for io::Error {
105 105
 impl StdError for Error {
106 106
     fn description(&self) -> &str {
107 107
         match *self.0 {
108
-            ErrorKind::Io(ref err) => err.description(),
109
-            ErrorKind::Protobuf { ref err, .. } => err.description(),
110
-            ErrorKind::StringtableUtf8 { ref err, .. } => err.description(),
108
+            ErrorKind::Io(ref err, ..) => {
109
+                use std::io::ErrorKind;
110
+                match err.kind() {
111
+                    ErrorKind::NotFound => "io error: not found",
112
+                    ErrorKind::PermissionDenied => "io error: permission denied",
113
+                    ErrorKind::ConnectionRefused => "io error: connection refused",
114
+                    ErrorKind::ConnectionReset => "io error: connection reset",
115
+                    ErrorKind::ConnectionAborted => "io error: connection aborted",
116
+                    ErrorKind::NotConnected => "io error: not connected",
117
+                    ErrorKind::AddrInUse => "io error: address in use",
118
+                    ErrorKind::AddrNotAvailable => "io error: address not available",
119
+                    ErrorKind::BrokenPipe => "io error: broken pipe",
120
+                    ErrorKind::AlreadyExists => "io error: already exists",
121
+                    ErrorKind::WouldBlock => "io error: would block",
122
+                    ErrorKind::InvalidInput => "io error: invalid input",
123
+                    ErrorKind::InvalidData => "io error: invalid data",
124
+                    ErrorKind::TimedOut => "io error: timed out",
125
+                    ErrorKind::WriteZero => "io error: write zero",
126
+                    ErrorKind::Interrupted => "io error: interrupted",
127
+                    ErrorKind::Other => "io error: other",
128
+                    ErrorKind::UnexpectedEof => "io error: unexpected EOF",
129
+                    _ => "io error",
130
+                }
131
+            }
132
+            ErrorKind::Protobuf { .. } => "protobuf error",
133
+            ErrorKind::StringtableUtf8 { .. } => "UTF-8 error in stringtable",
111 134
             ErrorKind::StringtableIndexOutOfBounds { .. } => "stringtable index out of bounds",
112 135
             ErrorKind::Blob(BlobError::InvalidHeaderSize) => {
113 136
                 "blob header size could not be decoded"

+ 7
- 8
src/indexed.rs 查看文件

@@ -129,11 +129,7 @@ impl<R: Read + Seek + Send> IndexedReader<R> {
129 129
     /// # }
130 130
     /// # foo().unwrap();
131 131
     /// ```
132
-    pub fn read_ways_and_deps<F, E>(
133
-        &mut self,
134
-        mut filter: F,
135
-        mut element_callback: E,
136
-    ) -> Result<()>
132
+    pub fn read_ways_and_deps<F, E>(&mut self, mut filter: F, mut element_callback: E) -> Result<()>
137 133
     where
138 134
         F: for<'a> FnMut(&Way<'a>) -> bool,
139 135
         E: for<'a> FnMut(&Element<'a>),
@@ -202,10 +198,13 @@ impl<R: Read + Seek + Send> IndexedReader<R> {
202 198
         //   * Iterate only over blobs that may include the node IDs we're searching for
203 199
         for info in &mut self.index {
204 200
             if info.blob_type == SimpleBlobType::Primitive {
205
-                if let Some(node_id_range) = info.id_ranges.as_ref().and_then(|r| r.node_ids.as_ref()) {
201
+                if let Some(node_id_range) =
202
+                    info.id_ranges.as_ref().and_then(|r| r.node_ids.as_ref())
203
+                {
206 204
                     if range_included(node_id_range.clone(), &node_ids) {
207 205
                         //TODO Only collect into Vec if range has a reasonable size
208
-                        let node_ids: Vec<i64> = node_ids.range(node_id_range.clone()).map(|x| *x).collect();
206
+                        let node_ids: Vec<i64> =
207
+                            node_ids.range(node_id_range.clone()).copied().collect();
209 208
                         self.reader.seek(info.offset)?;
210 209
                         let blob = self.reader.next().ok_or_else(|| {
211 210
                             ::std::io::Error::new(
@@ -265,7 +264,7 @@ mod tests {
265 264
     #[test]
266 265
     fn test_range_included_set() {
267 266
         let mut set = BTreeSet::<i64>::new();
268
-        set.extend(&[1,2,6]);
267
+        set.extend(&[1, 2, 6]);
269 268
 
270 269
         assert_eq!(range_included(RangeInclusive::new(0, 0), &set), false);
271 270
         assert_eq!(range_included(RangeInclusive::new(1, 1), &set), true);

+ 17
- 15
tests/read.rs 查看文件

@@ -207,21 +207,23 @@ fn read_ways_and_deps() {
207 207
         let mut ways = 0;
208 208
         let mut nodes = 0;
209 209
 
210
-        reader.read_ways_and_deps(
211
-            |way| {
212
-                way.tags()
213
-                   .find(|&key_value| key_value == ("building", "yes"))
214
-                   .is_some()
215
-            },
216
-            |element| {
217
-                match element {
218
-                    Element::Way(_) => ways += 1,
219
-                    Element::Node(_) => nodes += 1,
220
-                    Element::DenseNode(_) => nodes += 1,
221
-                    Element::Relation(_) => panic!(), // should not occur
222
-                }
223
-            },
224
-        ).unwrap();
210
+        reader
211
+            .read_ways_and_deps(
212
+                |way| {
213
+                    way.tags()
214
+                        .find(|&key_value| key_value == ("building", "yes"))
215
+                        .is_some()
216
+                },
217
+                |element| {
218
+                    match element {
219
+                        Element::Way(_) => ways += 1,
220
+                        Element::Node(_) => nodes += 1,
221
+                        Element::DenseNode(_) => nodes += 1,
222
+                        Element::Relation(_) => panic!(), // should not occur
223
+                    }
224
+                },
225
+            )
226
+            .unwrap();
225 227
 
226 228
         assert_eq!(ways, 1);
227 229
         assert_eq!(nodes, 3);