Skip to content

Commit 93dcad2

Browse files
authored
Try #48:
2 parents 1736b26 + 3e7770c commit 93dcad2

File tree

5 files changed

+60
-56
lines changed

5 files changed

+60
-56
lines changed

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ edition = "2018"
1111

1212
[dependencies]
1313
thiserror = "1.0"
14-
geo-types = "0.6"
14+
geo-types = "0.7"
1515
num-traits = "0.2"
1616
serde = { version = "1.0", features = ["derive"] }
1717
serde_json = "1.0"
18-
reqwest = { version = "0.11", default-features = false, features = ["default-tls", "blocking", "json"] }
19-
hyper = "0.14.11"
18+
reqwest = { version = "0.11", default-features = false, features = [
19+
"default-tls",
20+
"blocking",
21+
"json",
22+
] }
23+
hyper = "0.14"
2024
chrono = { version = "0.4", features = ["serde"] }
2125

2226
[features]

src/geoadmin.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use crate::Point;
2222
use crate::UA_STRING;
2323
use crate::{Client, HeaderMap, HeaderValue, USER_AGENT};
2424
use crate::{Forward, Reverse};
25-
use num_traits::{Float, Pow};
25+
use geo_types::CoordFloat;
26+
use num_traits::Pow;
2627

2728
/// An instance of the GeoAdmin geocoding service
2829
pub struct GeoAdmin {
@@ -34,7 +35,7 @@ pub struct GeoAdmin {
3435
/// An instance of a parameter builder for GeoAdmin geocoding
3536
pub struct GeoAdminParams<'a, T>
3637
where
37-
T: Float,
38+
T: CoordFloat,
3839
{
3940
searchtext: &'a str,
4041
origins: &'a str,
@@ -44,7 +45,7 @@ where
4445

4546
impl<'a, T> GeoAdminParams<'a, T>
4647
where
47-
T: Float,
48+
T: CoordFloat,
4849
{
4950
/// Create a new GeoAdmin parameter builder
5051
/// # Example:
@@ -159,7 +160,7 @@ impl GeoAdmin {
159160
params: &GeoAdminParams<T>,
160161
) -> Result<GeoAdminForwardResponse<T>, GeocodingError>
161162
where
162-
T: Float,
163+
T: CoordFloat,
163164
for<'de> T: Deserialize<'de>,
164165
{
165166
// For lifetime issues
@@ -219,7 +220,7 @@ impl Default for GeoAdmin {
219220

220221
impl<T> Forward<T> for GeoAdmin
221222
where
222-
T: Float,
223+
T: CoordFloat,
223224
for<'de> T: Deserialize<'de>,
224225
{
225226
/// A forward-geocoding lookup of an address. Please see [the documentation](https://api3.geo.admin.ch/services/sdiservices.html#search) for details.
@@ -258,7 +259,7 @@ where
258259

259260
impl<T> Reverse<T> for GeoAdmin
260261
where
261-
T: Float,
262+
T: CoordFloat,
262263
for<'de> T: Deserialize<'de>,
263264
{
264265
/// A reverse lookup of a point. More detail on the format of the
@@ -309,7 +310,7 @@ where
309310
// 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
310311
fn wgs84_to_lv03<T>(p: &Point<T>) -> Point<T>
311312
where
312-
T: Float,
313+
T: CoordFloat,
313314
{
314315
let lambda = (p.x().to_f64().unwrap() * 3600.0 - 26782.5) / 10000.0;
315316
let phi = (p.y().to_f64().unwrap() * 3600.0 - 169028.66) / 10000.0;
@@ -356,7 +357,7 @@ where
356357
#[derive(Debug, Deserialize)]
357358
pub struct GeoAdminForwardResponse<T>
358359
where
359-
T: Float,
360+
T: CoordFloat,
360361
{
361362
pub features: Vec<GeoAdminForwardLocation<T>>,
362363
}
@@ -365,7 +366,7 @@ where
365366
#[derive(Debug, Deserialize)]
366367
pub struct GeoAdminForwardLocation<T>
367368
where
368-
T: Float,
369+
T: CoordFloat,
369370
{
370371
id: Option<usize>,
371372
pub properties: ForwardLocationProperties<T>,
@@ -454,7 +455,7 @@ mod test {
454455
fn new_with_sr_forward_test() {
455456
let geoadmin = GeoAdmin::new().with_sr("2056");
456457
let address = "Seftigenstrasse 264, 3084 Wabern";
457-
let res = geoadmin.forward(&address);
458+
let res = geoadmin.forward(address);
458459
assert_eq!(res.unwrap(), vec![Point::new(2_600_968.75, 1_197_427.0)]);
459460
}
460461

@@ -463,7 +464,7 @@ mod test {
463464
let geoadmin =
464465
GeoAdmin::new().with_endpoint("https://api3.geo.admin.ch/rest/services/api/");
465466
let address = "Seftigenstrasse 264, 3084 Wabern";
466-
let res = geoadmin.forward(&address);
467+
let res = geoadmin.forward(address);
467468
assert_eq!(
468469
res.unwrap(),
469470
vec![Point::new(7.451352119445801, 46.92793655395508)]
@@ -474,7 +475,7 @@ mod test {
474475
fn with_sr_forward_full_test() {
475476
let geoadmin = GeoAdmin::new().with_sr("2056");
476477
let bbox = InputBounds::new((2_600_967.75, 1_197_426.0), (2_600_969.75, 1_197_428.0));
477-
let params = GeoAdminParams::new(&"Seftigenstrasse Bern")
478+
let params = GeoAdminParams::new("Seftigenstrasse Bern")
478479
.with_origins("address")
479480
.with_bbox(&bbox)
480481
.build();
@@ -490,7 +491,7 @@ mod test {
490491
fn forward_full_test() {
491492
let geoadmin = GeoAdmin::new();
492493
let bbox = InputBounds::new((7.4513398, 46.92792859), (7.4513662, 46.9279467));
493-
let params = GeoAdminParams::new(&"Seftigenstrasse Bern")
494+
let params = GeoAdminParams::new("Seftigenstrasse Bern")
494495
.with_origins("address")
495496
.with_bbox(&bbox)
496497
.build();
@@ -506,7 +507,7 @@ mod test {
506507
fn forward_test() {
507508
let geoadmin = GeoAdmin::new();
508509
let address = "Seftigenstrasse 264, 3084 Wabern";
509-
let res = geoadmin.forward(&address);
510+
let res = geoadmin.forward(address);
510511
assert_eq!(
511512
res.unwrap(),
512513
vec![Point::new(7.451352119445801, 46.92793655395508)]

src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
2828
static UA_STRING: &str = "Rust-Geocoding";
2929

30-
use chrono;
30+
use geo_types::CoordFloat;
3131
pub use geo_types::{Coordinate, Point};
32-
use num_traits::Float;
3332
use reqwest::blocking::Client;
3433
use reqwest::header::ToStrError;
3534
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
@@ -85,7 +84,7 @@ pub enum GeocodingError {
8584
/// ```
8685
pub trait Reverse<T>
8786
where
88-
T: Float,
87+
T: CoordFloat,
8988
{
9089
// NOTE TO IMPLEMENTERS: Point coordinates are lon, lat (x, y)
9190
// You may have to provide these coordinates in reverse order,
@@ -113,7 +112,7 @@ where
113112
/// ```
114113
pub trait Forward<T>
115114
where
116-
T: Float,
115+
T: CoordFloat,
117116
{
118117
// NOTE TO IMPLEMENTERS: while returned provider point data may not be in
119118
// lon, lat (x, y) order, Geocoding requires this order in its output Point
@@ -128,15 +127,15 @@ where
128127
#[derive(Copy, Clone, Debug)]
129128
pub struct InputBounds<T>
130129
where
131-
T: Float,
130+
T: CoordFloat,
132131
{
133132
pub minimum_lonlat: Point<T>,
134133
pub maximum_lonlat: Point<T>,
135134
}
136135

137136
impl<T> InputBounds<T>
138137
where
139-
T: Float,
138+
T: CoordFloat,
140139
{
141140
/// Create a new `InputBounds` struct by passing 2 `Point`s defining:
142141
/// - minimum (bottom-left) longitude and latitude coordinates
@@ -155,7 +154,7 @@ where
155154
/// Convert borrowed input bounds into the correct String representation
156155
impl<T> From<InputBounds<T>> for String
157156
where
158-
T: Float,
157+
T: CoordFloat,
159158
{
160159
fn from(ip: InputBounds<T>) -> String {
161160
// Return in lon, lat order

src/opencage.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
//! // "Carrer de Calatrava, 68, 08017 Barcelone, Espagne"
2525
//! println!("{:?}", res.unwrap());
2626
//! ```
27-
use crate::chrono::naive::serde::ts_seconds::deserialize as from_ts;
28-
use crate::chrono::NaiveDateTime;
2927
use crate::DeserializeOwned;
3028
use crate::GeocodingError;
3129
use crate::InputBounds;
@@ -34,7 +32,9 @@ use crate::UA_STRING;
3432
use crate::{Client, HeaderMap, HeaderValue, USER_AGENT};
3533
use crate::{Deserialize, Serialize};
3634
use crate::{Forward, Reverse};
37-
use num_traits::Float;
35+
use chrono::naive::serde::ts_seconds::deserialize as from_ts;
36+
use chrono::NaiveDateTime;
37+
use geo_types::CoordFloat;
3838
use serde::Deserializer;
3939
use std::collections::HashMap;
4040
use std::sync::{Arc, Mutex};
@@ -146,7 +146,7 @@ impl<'a> Opencage<'a> {
146146
///```
147147
pub fn reverse_full<T>(&self, point: &Point<T>) -> Result<OpencageResponse<T>, GeocodingError>
148148
where
149-
T: Float + DeserializeOwned,
149+
T: CoordFloat + DeserializeOwned,
150150
{
151151
let q = format!(
152152
"{}, {}",
@@ -156,9 +156,9 @@ impl<'a> Opencage<'a> {
156156
);
157157
let mut query = vec![
158158
("q", q.as_str()),
159-
(&"key", &self.api_key),
160-
(&"no_annotations", "0"),
161-
(&"no_record", "1"),
159+
("key", &self.api_key),
160+
("no_annotations", "0"),
161+
("no_record", "1"),
162162
];
163163
query.extend(self.parameters.as_query());
164164

@@ -248,7 +248,7 @@ impl<'a> Opencage<'a> {
248248
bounds: U,
249249
) -> Result<OpencageResponse<T>, GeocodingError>
250250
where
251-
T: Float + DeserializeOwned,
251+
T: CoordFloat + DeserializeOwned,
252252
U: Into<Option<InputBounds<T>>>,
253253
{
254254
let ann = String::from("0");
@@ -291,7 +291,7 @@ impl<'a> Opencage<'a> {
291291

292292
impl<'a, T> Reverse<T> for Opencage<'a>
293293
where
294-
T: Float + DeserializeOwned,
294+
T: CoordFloat + DeserializeOwned,
295295
{
296296
/// A reverse lookup of a point. More detail on the format of the
297297
/// returned `String` can be found [here](https://blog.opencagedata.com/post/99059889253/good-looking-addresses-solving-the-berlin-berlin)
@@ -336,7 +336,7 @@ where
336336

337337
impl<'a, T> Forward<T> for Opencage<'a>
338338
where
339-
T: Float + DeserializeOwned,
339+
T: CoordFloat + DeserializeOwned,
340340
{
341341
/// A forward-geocoding lookup of an address. Please see [the documentation](https://opencagedata.com/api#ambiguous-results) for details
342342
/// of best practices in order to obtain good-quality results.
@@ -511,7 +511,7 @@ where
511511
#[derive(Debug, Serialize, Deserialize)]
512512
pub struct OpencageResponse<T>
513513
where
514-
T: Float,
514+
T: CoordFloat,
515515
{
516516
pub documentation: String,
517517
pub licenses: Vec<HashMap<String, String>>,
@@ -528,7 +528,7 @@ where
528528
#[derive(Debug, Clone, Serialize, Deserialize)]
529529
pub struct Results<T>
530530
where
531-
T: Float,
531+
T: CoordFloat,
532532
{
533533
pub annotations: Option<Annotations<T>>,
534534
pub bounds: Option<Bounds<T>>,
@@ -542,7 +542,7 @@ where
542542
#[derive(Debug, Clone, Serialize, Deserialize)]
543543
pub struct Annotations<T>
544544
where
545-
T: Float,
545+
T: CoordFloat,
546546
{
547547
pub dms: Option<HashMap<String, String>>,
548548
pub mgrs: Option<String>,
@@ -615,7 +615,7 @@ pub struct Timestamp {
615615
#[derive(Debug, Clone, Serialize, Deserialize)]
616616
pub struct Bounds<T>
617617
where
618-
T: Float,
618+
T: CoordFloat,
619619
{
620620
pub northeast: HashMap<String, T>,
621621
pub southwest: HashMap<String, T>,
@@ -652,7 +652,7 @@ mod test {
652652
fn forward_test() {
653653
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
654654
let address = "Schwabing, München";
655-
let res = oc.forward(&address);
655+
let res = oc.forward(address);
656656
assert_eq!(
657657
res.unwrap(),
658658
vec![Point(Coordinate {
@@ -678,7 +678,7 @@ mod test {
678678
minimum_lonlat: Point::new(-0.13806939125061035, 51.51989264641164),
679679
maximum_lonlat: Point::new(-0.13427138328552246, 51.52319711775629),
680680
};
681-
let res = oc.forward_full(&address, bbox).unwrap();
681+
let res = oc.forward_full(address, bbox).unwrap();
682682
let first_result = &res.results[0];
683683
assert!(first_result.formatted.contains("UCL"));
684684
}
@@ -690,7 +690,7 @@ mod test {
690690
Point::new(-0.13806939125061035, 51.51989264641164),
691691
Point::new(-0.13427138328552246, 51.52319711775629),
692692
);
693-
let res = oc.forward_full(&address, bbox).unwrap();
693+
let res = oc.forward_full(address, bbox).unwrap();
694694
let first_result = &res.results[0];
695695
assert!(first_result
696696
.formatted
@@ -704,7 +704,7 @@ mod test {
704704
Point::from((-0.13806939125061035, 51.51989264641164)),
705705
Point::from((-0.13427138328552246, 51.52319711775629)),
706706
);
707-
let res = oc.forward_full(&address, bbox).unwrap();
707+
let res = oc.forward_full(address, bbox).unwrap();
708708
let first_result = &res.results[0];
709709
assert!(first_result
710710
.formatted
@@ -718,7 +718,7 @@ mod test {
718718
(-0.13806939125061035, 51.51989264641164),
719719
(-0.13427138328552246, 51.52319711775629),
720720
);
721-
let res = oc.forward_full(&address, bbox).unwrap();
721+
let res = oc.forward_full(address, bbox).unwrap();
722722
let first_result = &res.results[0];
723723
assert!(first_result
724724
.formatted
@@ -728,7 +728,7 @@ mod test {
728728
fn forward_full_test_nobox() {
729729
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
730730
let address = "Moabit, Berlin, Germany";
731-
let res = oc.forward_full(&address, NOBOX).unwrap();
731+
let res = oc.forward_full(address, NOBOX).unwrap();
732732
let first_result = &res.results[0];
733733
assert_eq!(first_result.formatted, "Moabit, Berlin, Germany");
734734
}

0 commit comments

Comments
 (0)