Skip to content

Commit c251b76

Browse files
authored
ci: Use GitHub Actions for CI (#53)
1 parent 16eb6ff commit c251b76

File tree

8 files changed

+69
-32
lines changed

8 files changed

+69
-32
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Sanity Checks
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Rust
14+
uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
components: rustfmt, clippy
18+
19+
- name: Check formatting
20+
run: cargo fmt --all -- --check
21+
22+
- name: Run Clippy
23+
run: cargo clippy -- -Dwarnings
24+
25+
- name: Run tests
26+
run: cargo test

examples/count.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate env_logger;
1111
extern crate osmpbfreader;
1212

1313
fn count<F: Fn(&osmpbfreader::Tags) -> bool>(filter: F, filename: &std::ffi::OsStr) {
14-
let r = std::fs::File::open(&std::path::Path::new(filename)).unwrap();
14+
let r = std::fs::File::open(std::path::Path::new(filename)).unwrap();
1515
let mut pbf = osmpbfreader::OsmPbfReader::new(r);
1616
let mut nb_nodes = 0;
1717
let mut sum_lon = 0.;

examples/count_with_deps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate env_logger;
1111
extern crate osmpbfreader;
1212

1313
fn count<F: Fn(&osmpbfreader::Tags) -> bool>(filter: F, filename: &std::ffi::OsStr) {
14-
let r = std::fs::File::open(&std::path::Path::new(filename)).unwrap();
14+
let r = std::fs::File::open(std::path::Path::new(filename)).unwrap();
1515
let mut pbf = osmpbfreader::OsmPbfReader::new(r);
1616
let objs = pbf.get_objs_and_deps(|obj| filter(obj.tags())).unwrap();
1717
let mut nb_nodes = 0;

examples/relation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn wanted(obj: &osmpbfreader::OsmObj) -> bool {
1414
fn main() {
1515
let filename = std::env::args_os().nth(1).unwrap();
1616
let path = std::path::Path::new(&filename);
17-
let r = std::fs::File::open(&path).unwrap();
17+
let r = std::fs::File::open(path).unwrap();
1818
let mut pbf = osmpbfreader::OsmPbfReader::new(r);
1919
let objects = pbf.get_objs_and_deps(wanted).unwrap();
2020
println!(

examples/tutorial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate osmpbfreader;
1010
fn main() {
1111
let filename = std::env::args_os().nth(1).unwrap();
1212
let path = std::path::Path::new(&filename);
13-
let r = std::fs::File::open(&path).unwrap();
13+
let r = std::fs::File::open(path).unwrap();
1414
let mut pbf = osmpbfreader::OsmPbfReader::new(r);
1515
let mut nb = 0;
1616
for _obj in pbf.iter().map(Result::unwrap) {

src/blobs.rs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,33 @@
99
1010
use 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+
};
1316
use crate::fileformat::Blob;
1417
use crate::objects::OsmObj;
1518
use crate::osmformat::PrimitiveBlock;
1619

1720
macro_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>`.
4648
pub struct OsmObjs<T: Iterator>(OsmObjsImpl<T>);
4749

50+
#[allow(clippy::type_complexity)]
4851
enum 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>>`.
6467
pub 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>>`.
7277
pub 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>>`.
8087
pub 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>>`.
8897
pub 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
}

src/objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Tags {
2929

3030
/// Returns if it contains a tag with the given `key` and `value`.
3131
pub fn contains(&self, key: &str, value: &str) -> bool {
32-
self.0.get(key).map_or(false, |v| v.as_str() == value)
32+
self.0.get(key).is_some_and(|v| v.as_str() == value)
3333
}
3434

3535
/// Consume tags into inner FlatMap representation

src/reader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ impl<R: io::Read> OsmPbfReader<R> {
127127
/// CPU usage are guaranteed to be bounded even if the caller stop
128128
/// consuming items.
129129
pub fn par_iter_relations(&mut self) -> RelationParIter<'_, R> {
130-
RelationParIter(self.blobs().par_flat_map(blobs::result_blob_into_relation_iter))
130+
RelationParIter(
131+
self.blobs()
132+
.par_flat_map(blobs::result_blob_into_relation_iter),
133+
)
131134
}
132135

133-
134-
135136
/// Rewinds the pbf file to the begining.
136137
///
137138
/// Useful if you want to read several consecutive times the same
@@ -367,7 +368,6 @@ pub_iterator_type! {
367368
where R: io::Read + 'a
368369
}
369370

370-
371371
pub_iterator_type! {
372372
#[doc="Iterator on the `OsmObj` of the pbf file."]
373373
RelationIter['a, R] = iter::FlatMap<Blobs<'a, R>, blobs::OsmObjs<blobs::OsmBlobRelations>, fn(Result<Blob>) -> blobs::OsmObjs<blobs::OsmBlobRelations>>

0 commit comments

Comments
 (0)