Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI and Clippy lints #63

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,28 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:proj-9.2.1-rust-1.70"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:proj-9.2.1-rust-1.71"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
- "georust/geo-ci:proj-9.4.0-rust-1.75"
# Two most recent releases - we omit older ones for expedient CI (TBD)
container:
image: ${{ matrix.container_image }}
steps:
- name: Install clippy and rustfmt
run: rustup component add clippy rustfmt
- name: Checkout repository
uses: actions/checkout@v3
- run: cargo install cargo-all-features
- run: cargo build-all-features
- run: cargo test-all-features
- name: Check formatting
run: cargo fmt --check
- name: Build (--no-default-features)
run: cargo build --no-default-features
- name: Test (--no-default-features)
run: cargo test --no-default-features
- name: Build (default features)
run: cargo build
- name: Test (default features)
run: cargo test
- name: Build (--all-features)
run: cargo build --all-features
- name: Test (--all-features)
run: cargo test --all-features
- name: Clippy
run: cargo clippy --all-features --all-targets
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ repository = "https://github.com/georust/geocoding"
keywords = ["gecoding", "geo", "gis", "geospatial"]
readme = "README.md"
edition = "2018"
rust-version = "1.69"
rust-version = "1.75"

[dependencies]
thiserror = "1.0"
geo-types = "0.7.8"
num-traits = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", default-features = false, features = ["default-tls", "blocking", "json"] }
reqwest = { version = "0.11", default-features = false, features = [
"default-tls",
"blocking",
"json",
] }
hyper = "0.14.11"

[features]
Expand Down
20 changes: 10 additions & 10 deletions src/geoadmin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl GeoAdmin {
];

if let Some(bb) = params.bbox.cloned().as_mut() {
if vec!["4326", "3857"].contains(&self.sr.as_str()) {
if ["4326", "3857"].contains(&self.sr.as_str()) {
*bb = InputBounds::new(
wgs84_to_lv03(&bb.minimum_lonlat),
wgs84_to_lv03(&bb.maximum_lonlat),
Expand All @@ -193,7 +193,7 @@ impl GeoAdmin {

let resp = self
.client
.get(&format!("{}SearchServer", self.endpoint))
.get(format!("{}SearchServer", self.endpoint))
.query(&query)
.send()?
.error_for_status()?;
Expand Down Expand Up @@ -229,7 +229,7 @@ where
fn forward(&self, place: &str) -> Result<Vec<Point<T>>, GeocodingError> {
let resp = self
.client
.get(&format!("{}SearchServer", self.endpoint))
.get(format!("{}SearchServer", self.endpoint))
.query(&[
("searchText", place),
("type", "locations"),
Expand All @@ -242,7 +242,7 @@ where
.error_for_status()?;
let res: GeoAdminForwardResponse<T> = resp.json()?;
// return easting & northing consistent
let results = if vec!["2056", "21781"].contains(&self.sr.as_str()) {
let results = if ["2056", "21781"].contains(&self.sr.as_str()) {
res.features
.iter()
.map(|feature| Point::new(feature.properties.y, feature.properties.x)) // y = west-east, x = north-south
Expand All @@ -269,7 +269,7 @@ where
fn reverse(&self, point: &Point<T>) -> Result<Option<String>, GeocodingError> {
let resp = self
.client
.get(&format!("{}MapServer/identify", self.endpoint))
.get(format!("{}MapServer/identify", self.endpoint))
.query(&[
(
"geometry",
Expand Down Expand Up @@ -453,7 +453,7 @@ mod test {
fn new_with_sr_forward_test() {
let geoadmin = GeoAdmin::new().with_sr("2056");
let address = "Seftigenstrasse 264, 3084 Wabern";
let res = geoadmin.forward(&address);
let res = geoadmin.forward(address);
assert_eq!(res.unwrap(), vec![Point::new(2_600_968.75, 1_197_427.0)]);
}

Expand All @@ -462,7 +462,7 @@ mod test {
let geoadmin =
GeoAdmin::new().with_endpoint("https://api3.geo.admin.ch/rest/services/api/");
let address = "Seftigenstrasse 264, 3084 Wabern";
let res = geoadmin.forward(&address);
let res = geoadmin.forward(address);
assert_eq!(
res.unwrap(),
vec![Point::new(7.451352119445801, 46.92793655395508)]
Expand All @@ -473,7 +473,7 @@ mod test {
fn with_sr_forward_full_test() {
let geoadmin = GeoAdmin::new().with_sr("2056");
let bbox = InputBounds::new((2_600_967.75, 1_197_426.0), (2_600_969.75, 1_197_428.0));
let params = GeoAdminParams::new(&"Seftigenstrasse Bern")
let params = GeoAdminParams::new("Seftigenstrasse Bern")
.with_origins("address")
.with_bbox(&bbox)
.build();
Expand All @@ -489,7 +489,7 @@ mod test {
fn forward_full_test() {
let geoadmin = GeoAdmin::new();
let bbox = InputBounds::new((7.4513398, 46.92792859), (7.4513662, 46.9279467));
let params = GeoAdminParams::new(&"Seftigenstrasse Bern")
let params = GeoAdminParams::new("Seftigenstrasse Bern")
.with_origins("address")
.with_bbox(&bbox)
.build();
Expand All @@ -505,7 +505,7 @@ mod test {
fn forward_test() {
let geoadmin = GeoAdmin::new();
let address = "Seftigenstrasse 264, 3084 Wabern";
let res = geoadmin.forward(&address);
let res = geoadmin.forward(address);
assert_eq!(
res.unwrap(),
vec![Point::new(7.451352119445801, 46.92793655395508)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub enum GeocodingError {
/// let res = oc.reverse(&p).unwrap();
/// assert_eq!(
/// res,
/// Some("Carrer de Calatrava, 68, 08017 Barcelona, Spain".to_string())
/// Some("Carrer de Calatrava, 64, 08017 Barcelona, Spain".to_string())
/// );
/// ```
pub trait Reverse<T>
Expand Down
28 changes: 14 additions & 14 deletions src/opencage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! oc.parameters.language = Some("fr");
//! let p = Point::new(2.12870, 41.40139);
//! let res = oc.reverse(&p);
//! // "Carrer de Calatrava, 68, 08017 Barcelone, Espagne"
//! // "Carrer de Calatrava, 64, 08017 Barcelone, Espagne"
//! println!("{:?}", res.unwrap());
//! ```
use crate::DeserializeOwned;
Expand Down Expand Up @@ -96,7 +96,7 @@ pub struct Opencage<'a> {
remaining: Arc<Mutex<Option<i32>>>,
}

impl<'a> Opencage<'a> {
impl Opencage<'_> {
/// Create a new OpenCage geocoding instance
pub fn new(api_key: String) -> Self {
let mut headers = HeaderMap::new();
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<'a> Opencage<'a> {
}
}

impl<'a, T> Reverse<T> for Opencage<'a>
impl<T> Reverse<T> for Opencage<'_>
where
T: Float + DeserializeOwned + Debug,
{
Expand Down Expand Up @@ -333,7 +333,7 @@ where
}
}

impl<'a, T> Forward<T> for Opencage<'a>
impl<T> Forward<T> for Opencage<'_>
where
T: Float + DeserializeOwned + Debug,
{
Expand Down Expand Up @@ -476,15 +476,15 @@ where
/// "country": "Spain",
/// "country_code": "es",
/// "county": "BCN",
/// "house_number": "68",
/// "house_number": "64",
/// "political_union": "European Union",
/// "postcode": "08017",
/// "road": "Carrer de Calatrava",
/// "state": "Catalonia",
/// "suburb": "les Tres Torres"
/// },
/// "confidence": 10,
/// "formatted": "Carrer de Calatrava, 68, 08017 Barcelona, Spain",
/// "formatted": "Carrer de Calatrava, 64, 08017 Barcelona, Spain",
/// "geometry": {
/// "lat": 41.4014067,
/// "lng": 2.1287224
Expand Down Expand Up @@ -644,7 +644,7 @@ mod test {
let res = oc.reverse(&p);
assert_eq!(
res.unwrap(),
Some("Carrer de Calatrava, 68, 08017 Barcelona, Spain".to_string())
Some("Carrer de Calatrava, 64, 08017 Barcelona, Spain".to_string())
);
}

Expand All @@ -656,15 +656,15 @@ mod test {
let res = oc.reverse(&p);
assert_eq!(
res.unwrap(),
Some("Carrer de Calatrava, 68, 08017 Barcelone, Espagne".to_string())
Some("Carrer de Calatrava, 64, 08017 Barcelone, Espagne".to_string())
);
}
#[test]
#[allow(deprecated)]
fn forward_test() {
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
let address = "Schwabing, München";
let res = oc.forward(&address);
let res = oc.forward(address);
assert_eq!(
res.unwrap(),
vec![Point(Coord {
Expand All @@ -690,7 +690,7 @@ mod test {
minimum_lonlat: Point::new(-0.13806939125061035, 51.51989264641164),
maximum_lonlat: Point::new(-0.13427138328552246, 51.52319711775629),
};
let res = oc.forward_full(&address, bbox).unwrap();
let res = oc.forward_full(address, bbox).unwrap();
let first_result = &res.results[0];
assert!(first_result.formatted.contains("UCL"));
}
Expand All @@ -702,7 +702,7 @@ mod test {
Point::new(-0.13806939125061035, 51.51989264641164),
Point::new(-0.13427138328552246, 51.52319711775629),
);
let res = oc.forward_full(&address, bbox).unwrap();
let res = oc.forward_full(address, bbox).unwrap();
let first_result = &res.results[0];
assert!(
first_result.formatted.contains("UCL")
Expand All @@ -717,7 +717,7 @@ mod test {
Point::from((-0.13806939125061035, 51.51989264641164)),
Point::from((-0.13427138328552246, 51.52319711775629)),
);
let res = oc.forward_full(&address, bbox).unwrap();
let res = oc.forward_full(address, bbox).unwrap();
let first_result = &res.results[0];
assert!(
first_result.formatted.contains("UCL")
Expand All @@ -732,7 +732,7 @@ mod test {
(-0.13806939125061035, 51.51989264641164),
(-0.13427138328552246, 51.52319711775629),
);
let res = oc.forward_full(&address, bbox).unwrap();
let res = oc.forward_full(address, bbox).unwrap();
let first_result = &res.results[0];
assert!(first_result
.formatted
Expand All @@ -742,7 +742,7 @@ mod test {
fn forward_full_test_nobox() {
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
let address = "Moabit, Berlin, Germany";
let res = oc.forward_full(&address, NOBOX).unwrap();
let res = oc.forward_full(address, NOBOX).unwrap();
let first_result = &res.results[0];
assert_eq!(first_result.formatted, "Moabit, Berlin, Germany");
}
Expand Down
16 changes: 8 additions & 8 deletions src/openstreetmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Openstreetmap {

let resp = self
.client
.get(&format!("{}search", self.endpoint))
.get(format!("{}search", self.endpoint))
.query(&query)
.send()?
.error_for_status()?;
Expand All @@ -192,7 +192,7 @@ where
fn forward(&self, place: &str) -> Result<Vec<Point<T>>, GeocodingError> {
let resp = self
.client
.get(&format!("{}search", self.endpoint))
.get(format!("{}search", self.endpoint))
.query(&[(&"q", place), (&"format", &String::from("geojson"))])
.send()?
.error_for_status()?;
Expand All @@ -217,7 +217,7 @@ where
fn reverse(&self, point: &Point<T>) -> Result<Option<String>, GeocodingError> {
let resp = self
.client
.get(&format!("{}reverse", self.endpoint))
.get(format!("{}reverse", self.endpoint))
.query(&[
(&"lon", &point.x().to_f64().unwrap().to_string()),
(&"lat", &point.y().to_f64().unwrap().to_string()),
Expand Down Expand Up @@ -246,13 +246,13 @@ where
/// "place_id": 263681481,
/// "osm_type": "way",
/// "osm_id": 355421084,
/// "display_name": "68, Carrer de Calatrava, les Tres Torres, Sarrià - Sant Gervasi, Barcelona, BCN, Catalonia, 08017, Spain",
/// "display_name": "64, Carrer de Calatrava, les Tres Torres, Sarrià - Sant Gervasi, Barcelona, BCN, Catalonia, 08017, Spain",
/// "place_rank": 30,
/// "category": "building",
/// "type": "apartments",
/// "importance": 0.7409999999999999,
/// "address": {
/// "house_number": "68",
/// "house_number": "64",
/// "road": "Carrer de Calatrava",
/// "suburb": "les Tres Torres",
/// "city_district": "Sarrià - Sant Gervasi",
Expand Down Expand Up @@ -355,7 +355,7 @@ mod test {
let osm =
Openstreetmap::new_with_endpoint("https://nominatim.openstreetmap.org/".to_string());
let address = "Schwabing, München";
let res = osm.forward(&address);
let res = osm.forward(address);
assert_eq!(res.unwrap(), vec![Point::new(11.5884858, 48.1700887)]);
}

Expand All @@ -366,7 +366,7 @@ mod test {
(-0.13806939125061035, 51.51989264641164),
(-0.13427138328552246, 51.52319711775629),
);
let params = OpenstreetmapParams::new(&"UCL Centre for Advanced Spatial Analysis")
let params = OpenstreetmapParams::new("UCL Centre for Advanced Spatial Analysis")
.with_addressdetails(true)
.with_viewbox(&viewbox)
.build();
Expand All @@ -380,7 +380,7 @@ mod test {
fn forward_test() {
let osm = Openstreetmap::new();
let address = "Schwabing, München";
let res = osm.forward(&address);
let res = osm.forward(address);
assert_eq!(res.unwrap(), vec![Point::new(11.5884858, 48.1700887)]);
}

Expand Down
Loading