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

update dependencies, fix all clippy lints #48

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ 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.11", default-features = false, features = ["default-tls", "blocking", "json"] }
hyper = "0.14.11"
reqwest = { version = "0.11", default-features = false, features = [
"default-tls",
"blocking",
"json",
] }
hyper = "0.14"
chrono = { version = "0.4", features = ["serde"] }

[features]
Expand Down
29 changes: 15 additions & 14 deletions src/geoadmin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::Point;
use crate::UA_STRING;
use crate::{Client, HeaderMap, HeaderValue, USER_AGENT};
use crate::{Forward, Reverse};
use num_traits::{Float, Pow};
use geo_types::CoordFloat;
use num_traits::Pow;

/// An instance of the GeoAdmin geocoding service
pub struct GeoAdmin {
Expand All @@ -34,7 +35,7 @@ pub struct GeoAdmin {
/// An instance of a parameter builder for GeoAdmin geocoding
pub struct GeoAdminParams<'a, T>
where
T: Float,
T: CoordFloat,
{
searchtext: &'a str,
origins: &'a str,
Expand All @@ -44,7 +45,7 @@ where

impl<'a, T> GeoAdminParams<'a, T>
where
T: Float,
T: CoordFloat,
{
/// Create a new GeoAdmin parameter builder
/// # Example:
Expand Down Expand Up @@ -159,7 +160,7 @@ impl GeoAdmin {
params: &GeoAdminParams<T>,
) -> Result<GeoAdminForwardResponse<T>, GeocodingError>
where
T: Float,
T: CoordFloat,
for<'de> T: Deserialize<'de>,
{
// For lifetime issues
Expand Down Expand Up @@ -219,7 +220,7 @@ impl Default for GeoAdmin {

impl<T> Forward<T> for GeoAdmin
where
T: Float,
T: CoordFloat,
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.
Expand Down Expand Up @@ -258,7 +259,7 @@ where

impl<T> Reverse<T> for GeoAdmin
where
T: Float,
T: CoordFloat,
for<'de> T: Deserialize<'de>,
{
/// A reverse lookup of a point. More detail on the format of the
Expand Down Expand Up @@ -309,7 +310,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<T>(p: &Point<T>) -> Point<T>
where
T: Float,
T: CoordFloat,
{
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;
Expand Down Expand Up @@ -356,7 +357,7 @@ where
#[derive(Debug, Deserialize)]
pub struct GeoAdminForwardResponse<T>
where
T: Float,
T: CoordFloat,
{
pub features: Vec<GeoAdminForwardLocation<T>>,
}
Expand All @@ -365,7 +366,7 @@ where
#[derive(Debug, Deserialize)]
pub struct GeoAdminForwardLocation<T>
where
T: Float,
T: CoordFloat,
{
id: Option<usize>,
pub properties: ForwardLocationProperties<T>,
Expand Down Expand Up @@ -454,7 +455,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 @@ -463,7 +464,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 @@ -474,7 +475,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 @@ -490,7 +491,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 @@ -506,7 +507,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
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@

static UA_STRING: &str = "Rust-Geocoding";

use chrono;
use geo_types::CoordFloat;
pub use geo_types::{Coordinate, Point};
use num_traits::Float;
use reqwest::blocking::Client;
use reqwest::header::ToStrError;
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
Expand Down Expand Up @@ -85,7 +84,7 @@ pub enum GeocodingError {
/// ```
pub trait Reverse<T>
where
T: Float,
T: CoordFloat,
{
// NOTE TO IMPLEMENTERS: Point coordinates are lon, lat (x, y)
// You may have to provide these coordinates in reverse order,
Expand Down Expand Up @@ -113,7 +112,7 @@ where
/// ```
pub trait Forward<T>
where
T: Float,
T: CoordFloat,
{
// 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
Expand All @@ -128,15 +127,15 @@ where
#[derive(Copy, Clone, Debug)]
pub struct InputBounds<T>
where
T: Float,
T: CoordFloat,
{
pub minimum_lonlat: Point<T>,
pub maximum_lonlat: Point<T>,
}

impl<T> InputBounds<T>
where
T: Float,
T: CoordFloat,
{
/// Create a new `InputBounds` struct by passing 2 `Point`s defining:
/// - minimum (bottom-left) longitude and latitude coordinates
Expand All @@ -155,7 +154,7 @@ where
/// Convert borrowed input bounds into the correct String representation
impl<T> From<InputBounds<T>> for String
where
T: Float,
T: CoordFloat,
{
fn from(ip: InputBounds<T>) -> String {
// Return in lon, lat order
Expand Down
40 changes: 20 additions & 20 deletions src/opencage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +32,9 @@ use crate::UA_STRING;
use crate::{Client, HeaderMap, HeaderValue, USER_AGENT};
use crate::{Deserialize, Serialize};
use crate::{Forward, Reverse};
use num_traits::Float;
use chrono::naive::serde::ts_seconds::deserialize as from_ts;
use chrono::NaiveDateTime;
use geo_types::CoordFloat;
use serde::Deserializer;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<'a> Opencage<'a> {
///```
pub fn reverse_full<T>(&self, point: &Point<T>) -> Result<OpencageResponse<T>, GeocodingError>
where
T: Float + DeserializeOwned,
T: CoordFloat + DeserializeOwned,
{
let q = format!(
"{}, {}",
Expand All @@ -156,9 +156,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());

Expand Down Expand Up @@ -248,7 +248,7 @@ impl<'a> Opencage<'a> {
bounds: U,
) -> Result<OpencageResponse<T>, GeocodingError>
where
T: Float + DeserializeOwned,
T: CoordFloat + DeserializeOwned,
U: Into<Option<InputBounds<T>>>,
{
let ann = String::from("0");
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<'a> Opencage<'a> {

impl<'a, T> Reverse<T> for Opencage<'a>
where
T: Float + DeserializeOwned,
T: CoordFloat + DeserializeOwned,
{
/// 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)
Expand Down Expand Up @@ -336,7 +336,7 @@ where

impl<'a, T> Forward<T> for Opencage<'a>
where
T: Float + DeserializeOwned,
T: CoordFloat + DeserializeOwned,
{
/// 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.
Expand Down Expand Up @@ -511,7 +511,7 @@ where
#[derive(Debug, Serialize, Deserialize)]
pub struct OpencageResponse<T>
where
T: Float,
T: CoordFloat,
{
pub documentation: String,
pub licenses: Vec<HashMap<String, String>>,
Expand All @@ -528,7 +528,7 @@ where
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Results<T>
where
T: Float,
T: CoordFloat,
{
pub annotations: Option<Annotations<T>>,
pub bounds: Option<Bounds<T>>,
Expand All @@ -542,7 +542,7 @@ where
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Annotations<T>
where
T: Float,
T: CoordFloat,
{
pub dms: Option<HashMap<String, String>>,
pub mgrs: Option<String>,
Expand Down Expand Up @@ -615,7 +615,7 @@ pub struct Timestamp {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bounds<T>
where
T: Float,
T: CoordFloat,
{
pub northeast: HashMap<String, T>,
pub southwest: HashMap<String, T>,
Expand Down Expand Up @@ -652,7 +652,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 {
Expand All @@ -678,7 +678,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 @@ -690,7 +690,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
Expand All @@ -704,7 +704,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
Expand All @@ -718,7 +718,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 @@ -728,7 +728,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
Loading