24
24
//! // "Carrer de Calatrava, 68, 08017 Barcelone, Espagne"
25
25
//! println!("{:?}", res.unwrap());
26
26
//! ```
27
- use crate :: chrono:: naive:: serde:: ts_seconds:: deserialize as from_ts;
28
- use crate :: chrono:: NaiveDateTime ;
29
27
use crate :: DeserializeOwned ;
30
28
use crate :: GeocodingError ;
31
29
use crate :: InputBounds ;
@@ -34,9 +32,12 @@ use crate::UA_STRING;
34
32
use crate :: { Client , HeaderMap , HeaderValue , USER_AGENT } ;
35
33
use crate :: { Deserialize , Serialize } ;
36
34
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 ;
38
38
use serde:: Deserializer ;
39
39
use std:: collections:: HashMap ;
40
+ use std:: fmt:: Debug ;
40
41
use std:: sync:: { Arc , Mutex } ;
41
42
42
43
macro_rules! add_optional_param {
@@ -146,7 +147,7 @@ impl<'a> Opencage<'a> {
146
147
///```
147
148
pub fn reverse_full < T > ( & self , point : & Point < T > ) -> Result < OpencageResponse < T > , GeocodingError >
148
149
where
149
- T : Float + DeserializeOwned ,
150
+ T : CoordFloat + DeserializeOwned ,
150
151
{
151
152
let q = format ! (
152
153
"{}, {}" ,
@@ -156,9 +157,9 @@ impl<'a> Opencage<'a> {
156
157
) ;
157
158
let mut query = vec ! [
158
159
( "q" , q. as_str( ) ) ,
159
- ( & "key" , & self . api_key) ,
160
- ( & "no_annotations" , "0" ) ,
161
- ( & "no_record" , "1" ) ,
160
+ ( "key" , & self . api_key) ,
161
+ ( "no_annotations" , "0" ) ,
162
+ ( "no_record" , "1" ) ,
162
163
] ;
163
164
query. extend ( self . parameters . as_query ( ) ) ;
164
165
@@ -248,7 +249,7 @@ impl<'a> Opencage<'a> {
248
249
bounds : U ,
249
250
) -> Result < OpencageResponse < T > , GeocodingError >
250
251
where
251
- T : Float + DeserializeOwned ,
252
+ T : CoordFloat + DeserializeOwned ,
252
253
U : Into < Option < InputBounds < T > > > ,
253
254
{
254
255
let ann = String :: from ( "0" ) ;
@@ -291,7 +292,7 @@ impl<'a> Opencage<'a> {
291
292
292
293
impl < ' a , T > Reverse < T > for Opencage < ' a >
293
294
where
294
- T : Float + DeserializeOwned ,
295
+ T : CoordFloat + DeserializeOwned ,
295
296
{
296
297
/// A reverse lookup of a point. More detail on the format of the
297
298
/// returned `String` can be found [here](https://blog.opencagedata.com/post/99059889253/good-looking-addresses-solving-the-berlin-berlin)
@@ -336,7 +337,7 @@ where
336
337
337
338
impl < ' a , T > Forward < T > for Opencage < ' a >
338
339
where
339
- T : Float + DeserializeOwned ,
340
+ T : CoordFloat + DeserializeOwned ,
340
341
{
341
342
/// A forward-geocoding lookup of an address. Please see [the documentation](https://opencagedata.com/api#ambiguous-results) for details
342
343
/// of best practices in order to obtain good-quality results.
@@ -511,7 +512,7 @@ where
511
512
#[ derive( Debug , Serialize , Deserialize ) ]
512
513
pub struct OpencageResponse < T >
513
514
where
514
- T : Float ,
515
+ T : CoordFloat ,
515
516
{
516
517
pub documentation : String ,
517
518
pub licenses : Vec < HashMap < String , String > > ,
@@ -528,7 +529,7 @@ where
528
529
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
529
530
pub struct Results < T >
530
531
where
531
- T : Float ,
532
+ T : CoordFloat ,
532
533
{
533
534
pub annotations : Option < Annotations < T > > ,
534
535
pub bounds : Option < Bounds < T > > ,
@@ -542,7 +543,7 @@ where
542
543
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
543
544
pub struct Annotations < T >
544
545
where
545
- T : Float ,
546
+ T : CoordFloat ,
546
547
{
547
548
pub dms : Option < HashMap < String , String > > ,
548
549
pub mgrs : Option < String > ,
@@ -615,7 +616,7 @@ pub struct Timestamp {
615
616
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
616
617
pub struct Bounds < T >
617
618
where
618
- T : Float ,
619
+ T : CoordFloat ,
619
620
{
620
621
pub northeast : HashMap < String , T > ,
621
622
pub southwest : HashMap < String , T > ,
@@ -652,7 +653,7 @@ mod test {
652
653
fn forward_test ( ) {
653
654
let oc = Opencage :: new ( "dcdbf0d783374909b3debee728c7cc10" . to_string ( ) ) ;
654
655
let address = "Schwabing, München" ;
655
- let res = oc. forward ( & address) ;
656
+ let res = oc. forward ( address) ;
656
657
assert_eq ! (
657
658
res. unwrap( ) ,
658
659
vec![ Point ( Coordinate {
@@ -678,7 +679,7 @@ mod test {
678
679
minimum_lonlat : Point :: new ( -0.13806939125061035 , 51.51989264641164 ) ,
679
680
maximum_lonlat : Point :: new ( -0.13427138328552246 , 51.52319711775629 ) ,
680
681
} ;
681
- let res = oc. forward_full ( & address, bbox) . unwrap ( ) ;
682
+ let res = oc. forward_full ( address, bbox) . unwrap ( ) ;
682
683
let first_result = & res. results [ 0 ] ;
683
684
assert ! ( first_result. formatted. contains( "UCL" ) ) ;
684
685
}
@@ -690,7 +691,7 @@ mod test {
690
691
Point :: new ( -0.13806939125061035 , 51.51989264641164 ) ,
691
692
Point :: new ( -0.13427138328552246 , 51.52319711775629 ) ,
692
693
) ;
693
- let res = oc. forward_full ( & address, bbox) . unwrap ( ) ;
694
+ let res = oc. forward_full ( address, bbox) . unwrap ( ) ;
694
695
let first_result = & res. results [ 0 ] ;
695
696
assert ! ( first_result
696
697
. formatted
@@ -704,7 +705,7 @@ mod test {
704
705
Point :: from ( ( -0.13806939125061035 , 51.51989264641164 ) ) ,
705
706
Point :: from ( ( -0.13427138328552246 , 51.52319711775629 ) ) ,
706
707
) ;
707
- let res = oc. forward_full ( & address, bbox) . unwrap ( ) ;
708
+ let res = oc. forward_full ( address, bbox) . unwrap ( ) ;
708
709
let first_result = & res. results [ 0 ] ;
709
710
assert ! ( first_result
710
711
. formatted
@@ -718,7 +719,7 @@ mod test {
718
719
( -0.13806939125061035 , 51.51989264641164 ) ,
719
720
( -0.13427138328552246 , 51.52319711775629 ) ,
720
721
) ;
721
- let res = oc. forward_full ( & address, bbox) . unwrap ( ) ;
722
+ let res = oc. forward_full ( address, bbox) . unwrap ( ) ;
722
723
let first_result = & res. results [ 0 ] ;
723
724
assert ! ( first_result
724
725
. formatted
@@ -728,7 +729,7 @@ mod test {
728
729
fn forward_full_test_nobox ( ) {
729
730
let oc = Opencage :: new ( "dcdbf0d783374909b3debee728c7cc10" . to_string ( ) ) ;
730
731
let address = "Moabit, Berlin, Germany" ;
731
- let res = oc. forward_full ( & address, NOBOX ) . unwrap ( ) ;
732
+ let res = oc. forward_full ( address, NOBOX ) . unwrap ( ) ;
732
733
let first_result = & res. results [ 0 ] ;
733
734
assert_eq ! ( first_result. formatted, "Moabit, Berlin, Germany" ) ;
734
735
}
0 commit comments