From 6dff9c6037fcdbd7efbcae97d20bb997c8c37b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20R=C3=B6ssler?= Date: Tue, 10 Aug 2021 13:19:13 +0200 Subject: [PATCH] update dependencies, fix all clippy lints --- Cargo.toml | 14 ++++++++++---- src/geoadmin.rs | 28 +++++++++++++++------------- src/lib.rs | 12 ++++++------ src/opencage.rs | 39 ++++++++++++++++++++------------------- src/openstreetmap.rs | 24 +++++++++++++----------- 5 files changed, 64 insertions(+), 53 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 21f5b10..550f1e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,10 @@ name = "geocoding" description = "Geocoding library for Rust" version = "0.3.1" -authors = ["Stephan Hügel ", "Blake Grotewold "] +authors = [ + "Stephan Hügel ", + "Blake Grotewold ", +] license = "MIT OR Apache-2.0" repository = "https://github.com/georust/geocoding" keywords = ["gecoding", "geo", "gis", "geospatial"] @@ -11,12 +14,15 @@ edition = "2018" [dependencies] thiserror = "1.0" -geo-types = "0.6" +geo-types = "0.7" num-traits = "0.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -reqwest = { version = "0.10", default-features = false, features = ["blocking", "json"] } -hyper = "0.13.6" +reqwest = { version = "0.11", default-features = false, features = [ + "blocking", + "json", +] } +hyper = "0.14" chrono = { version = "0.4", features = ["serde"] } [features] diff --git a/src/geoadmin.rs b/src/geoadmin.rs index 7f0a78c..da667eb 100644 --- a/src/geoadmin.rs +++ b/src/geoadmin.rs @@ -15,6 +15,8 @@ //! let res = geoadmin.forward(&address); //! assert_eq!(res.unwrap(), vec![Point::new(7.451352119445801, 46.92793655395508)]); //! ``` +use std::fmt::Debug; + use crate::Deserialize; use crate::GeocodingError; use crate::InputBounds; @@ -34,7 +36,7 @@ pub struct GeoAdmin { /// An instance of a parameter builder for GeoAdmin geocoding pub struct GeoAdminParams<'a, T> where - T: Float, + T: Float + Debug, { searchtext: &'a str, origins: &'a str, @@ -44,7 +46,7 @@ where impl<'a, T> GeoAdminParams<'a, T> where - T: Float, + T: Float + Debug, { /// Create a new GeoAdmin parameter builder /// # Example: @@ -159,7 +161,7 @@ impl GeoAdmin { params: &GeoAdminParams, ) -> Result, GeocodingError> where - T: Float, + T: Float + Debug, for<'de> T: Deserialize<'de>, { // For lifetime issues @@ -219,7 +221,7 @@ impl Default for GeoAdmin { impl Forward for GeoAdmin where - T: Float, + T: Float + Debug, for<'de> T: Deserialize<'de>, { /// A forward-geocoding lookup of an address. Please see [the documentation](https://api3.geo.admin.ch/services/sdiservices.html#search) for details. @@ -258,7 +260,7 @@ where impl Reverse for GeoAdmin where - T: Float, + T: Float + Debug, for<'de> T: Deserialize<'de>, { /// A reverse lookup of a point. More detail on the format of the @@ -309,7 +311,7 @@ where // See [the documentation](https://www.swisstopo.admin.ch/content/swisstopo-internet/en/online/calculation-services/_jcr_content/contentPar/tabs/items/documents_publicatio/tabPar/downloadlist/downloadItems/19_1467104393233.download/ch1903wgs84_e.pdf) for more details fn wgs84_to_lv03(p: &Point) -> Point where - T: Float, + T: Float + Debug, { let lambda = (p.x().to_f64().unwrap() * 3600.0 - 26782.5) / 10000.0; let phi = (p.y().to_f64().unwrap() * 3600.0 - 169028.66) / 10000.0; @@ -356,7 +358,7 @@ where #[derive(Debug, Deserialize)] pub struct GeoAdminForwardResponse where - T: Float, + T: Float + Debug, { pub features: Vec>, } @@ -365,7 +367,7 @@ where #[derive(Debug, Deserialize)] pub struct GeoAdminForwardLocation where - T: Float, + T: Float + Debug, { id: Option, pub properties: ForwardLocationProperties, @@ -454,7 +456,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)]); } @@ -463,7 +465,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)] @@ -474,7 +476,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(); @@ -490,7 +492,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(); @@ -506,7 +508,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)] diff --git a/src/lib.rs b/src/lib.rs index f953c85..4279819 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,6 @@ static UA_STRING: &str = "Rust-Geocoding"; -use chrono; pub use geo_types::{Coordinate, Point}; use num_traits::Float; use reqwest::blocking::Client; @@ -35,6 +34,7 @@ use reqwest::header::ToStrError; use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; +use std::fmt::Debug; use std::num::ParseIntError; use thiserror::Error; @@ -85,7 +85,7 @@ pub enum GeocodingError { /// ``` pub trait Reverse where - T: Float, + T: Float + Debug, { // NOTE TO IMPLEMENTERS: Point coordinates are lon, lat (x, y) // You may have to provide these coordinates in reverse order, @@ -113,7 +113,7 @@ where /// ``` pub trait Forward where - T: Float, + T: Float + Debug, { // NOTE TO IMPLEMENTERS: while returned provider point data may not be in // lon, lat (x, y) order, Geocoding requires this order in its output Point @@ -128,7 +128,7 @@ where #[derive(Copy, Clone, Debug)] pub struct InputBounds where - T: Float, + T: Float + Debug, { pub minimum_lonlat: Point, pub maximum_lonlat: Point, @@ -136,7 +136,7 @@ where impl InputBounds where - T: Float, + T: Float + Debug, { /// Create a new `InputBounds` struct by passing 2 `Point`s defining: /// - minimum (bottom-left) longitude and latitude coordinates @@ -155,7 +155,7 @@ where /// Convert borrowed input bounds into the correct String representation impl From> for String where - T: Float, + T: Float + Debug, { fn from(ip: InputBounds) -> String { // Return in lon, lat order diff --git a/src/opencage.rs b/src/opencage.rs index b9a5bc7..5ea9dbc 100644 --- a/src/opencage.rs +++ b/src/opencage.rs @@ -24,8 +24,6 @@ //! // "Carrer de Calatrava, 68, 08017 Barcelone, Espagne" //! println!("{:?}", res.unwrap()); //! ``` -use crate::chrono::naive::serde::ts_seconds::deserialize as from_ts; -use crate::chrono::NaiveDateTime; use crate::DeserializeOwned; use crate::GeocodingError; use crate::InputBounds; @@ -34,9 +32,12 @@ use crate::UA_STRING; use crate::{Client, HeaderMap, HeaderValue, USER_AGENT}; use crate::{Deserialize, Serialize}; use crate::{Forward, Reverse}; +use chrono::naive::serde::ts_seconds::deserialize as from_ts; +use chrono::NaiveDateTime; use num_traits::Float; use serde::Deserializer; use std::collections::HashMap; +use std::fmt::Debug; use std::sync::{Arc, Mutex}; macro_rules! add_optional_param { @@ -146,7 +147,7 @@ impl<'a> Opencage<'a> { ///``` pub fn reverse_full(&self, point: &Point) -> Result, GeocodingError> where - T: Float + DeserializeOwned, + T: Float + DeserializeOwned + Debug, { let q = format!( "{}, {}", @@ -156,9 +157,9 @@ impl<'a> Opencage<'a> { ); let mut query = vec![ ("q", q.as_str()), - (&"key", &self.api_key), - (&"no_annotations", "0"), - (&"no_record", "1"), + ("key", &self.api_key), + ("no_annotations", "0"), + ("no_record", "1"), ]; query.extend(self.parameters.as_query()); @@ -248,7 +249,7 @@ impl<'a> Opencage<'a> { bounds: U, ) -> Result, GeocodingError> where - T: Float + DeserializeOwned, + T: Float + DeserializeOwned + Debug, U: Into>>, { let ann = String::from("0"); @@ -291,7 +292,7 @@ impl<'a> Opencage<'a> { impl<'a, T> Reverse for Opencage<'a> where - T: Float + DeserializeOwned, + T: Float + DeserializeOwned + Debug, { /// A reverse lookup of a point. More detail on the format of the /// returned `String` can be found [here](https://blog.opencagedata.com/post/99059889253/good-looking-addresses-solving-the-berlin-berlin) @@ -336,7 +337,7 @@ where impl<'a, T> Forward for Opencage<'a> where - T: Float + DeserializeOwned, + T: Float + DeserializeOwned + Debug, { /// A forward-geocoding lookup of an address. Please see [the documentation](https://opencagedata.com/api#ambiguous-results) for details /// of best practices in order to obtain good-quality results. @@ -511,7 +512,7 @@ where #[derive(Debug, Serialize, Deserialize)] pub struct OpencageResponse where - T: Float, + T: Float + Debug, { pub documentation: String, pub licenses: Vec>, @@ -528,7 +529,7 @@ where #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Results where - T: Float, + T: Float + Debug, { pub annotations: Option>, pub bounds: Option>, @@ -542,7 +543,7 @@ where #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Annotations where - T: Float, + T: Float + Debug, { pub dms: Option>, pub mgrs: Option, @@ -615,7 +616,7 @@ pub struct Timestamp { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Bounds where - T: Float, + T: Float + Debug, { pub northeast: HashMap, pub southwest: HashMap, @@ -652,7 +653,7 @@ mod test { 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(Coordinate { @@ -678,7 +679,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_eq!( first_result.formatted, @@ -693,7 +694,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_eq!( first_result.formatted, @@ -708,7 +709,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_eq!( first_result.formatted, @@ -723,7 +724,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_eq!( first_result.formatted, @@ -734,7 +735,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"); } diff --git a/src/openstreetmap.rs b/src/openstreetmap.rs index b223809..d4cdc11 100644 --- a/src/openstreetmap.rs +++ b/src/openstreetmap.rs @@ -16,6 +16,8 @@ //! let res = osm.forward(&address); //! assert_eq!(res.unwrap(), vec![Point::new(11.5884858, 48.1700887)]); //! ``` +use std::fmt::Debug; + use crate::GeocodingError; use crate::InputBounds; use crate::Point; @@ -34,7 +36,7 @@ pub struct Openstreetmap { /// An instance of a parameter builder for Openstreetmap geocoding pub struct OpenstreetmapParams<'a, T> where - T: Float, + T: Float + Debug, { query: &'a str, addressdetails: bool, @@ -43,7 +45,7 @@ where impl<'a, T> OpenstreetmapParams<'a, T> where - T: Float, + T: Float + Debug, { /// Create a new OpenStreetMap parameter builder /// # Example: @@ -144,7 +146,7 @@ impl Openstreetmap { params: &OpenstreetmapParams, ) -> Result, GeocodingError> where - T: Float, + T: Float + Debug, for<'de> T: Deserialize<'de>, { let format = String::from("geojson"); @@ -182,7 +184,7 @@ impl Default for Openstreetmap { impl Forward for Openstreetmap where - T: Float, + T: Float + Debug, for<'de> T: Deserialize<'de>, { /// A forward-geocoding lookup of an address. Please see [the documentation](https://nominatim.org/release-docs/develop/api/Search/) for details. @@ -206,7 +208,7 @@ where impl Reverse for Openstreetmap where - T: Float, + T: Float + Debug, for<'de> T: Deserialize<'de>, { /// A reverse lookup of a point. More detail on the format of the @@ -283,7 +285,7 @@ where #[derive(Debug, Serialize, Deserialize)] pub struct OpenstreetmapResponse where - T: Float, + T: Float + Debug, { pub r#type: String, pub licence: String, @@ -294,7 +296,7 @@ where #[derive(Debug, Serialize, Deserialize)] pub struct OpenstreetmapResult where - T: Float, + T: Float + Debug, { pub r#type: String, pub properties: ResultProperties, @@ -337,7 +339,7 @@ pub struct AddressDetails { #[derive(Debug, Serialize, Deserialize)] pub struct ResultGeometry where - T: Float, + T: Float + Debug, { pub r#type: String, pub coordinates: (T, T), @@ -352,7 +354,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)]); } @@ -363,7 +365,7 @@ mod test { (-0.13806939125061035, 51.51989264641164), (-0.13427138328552246, 51.52319711775629), ); - let params = OpenstreetmapParams::new(&"UCL CASA") + let params = OpenstreetmapParams::new("UCL CASA") .with_addressdetails(true) .with_viewbox(&viewbox) .build(); @@ -379,7 +381,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)]); }