1
1
extern crate geo;
2
2
3
- use self :: geo:: { Bbox , LineString , Point } ;
3
+ use self :: geo:: { Coordinate , LineString , Point , Rect } ;
4
4
use fallible_iterator:: FallibleIterator ;
5
5
use postgres_protocol:: types;
6
6
use std:: error:: Error ;
@@ -26,23 +26,21 @@ impl ToSql for Point<f64> {
26
26
to_sql_checked ! ( ) ;
27
27
}
28
28
29
- impl < ' a > FromSql < ' a > for Bbox < f64 > {
29
+ impl < ' a > FromSql < ' a > for Rect < f64 > {
30
30
fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < Self , Box < Error + Sync + Send > > {
31
- let bbox = types:: box_from_sql ( raw) ?;
32
- Ok ( Bbox {
33
- xmin : bbox. lower_left ( ) . x ( ) ,
34
- xmax : bbox. upper_right ( ) . x ( ) ,
35
- ymin : bbox. lower_left ( ) . y ( ) ,
36
- ymax : bbox. upper_right ( ) . y ( ) ,
31
+ let rect = types:: box_from_sql ( raw) ?;
32
+ Ok ( Rect {
33
+ min : Coordinate { x : rect. lower_left ( ) . x ( ) , y : rect. lower_left ( ) . y ( ) , } ,
34
+ max : Coordinate { x : rect. upper_right ( ) . x ( ) , y : rect. upper_right ( ) . y ( ) , } ,
37
35
} )
38
36
}
39
37
40
38
accepts ! ( BOX ) ;
41
39
}
42
40
43
- impl ToSql for Bbox < f64 > {
41
+ impl ToSql for Rect < f64 > {
44
42
fn to_sql ( & self , _: & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
45
- types:: box_to_sql ( self . xmin , self . ymin , self . xmax , self . ymax , out) ;
43
+ types:: box_to_sql ( self . min . x , self . min . y , self . max . x , self . max . y , out) ;
46
44
Ok ( IsNull :: No )
47
45
}
48
46
@@ -53,7 +51,7 @@ impl ToSql for Bbox<f64> {
53
51
impl < ' a > FromSql < ' a > for LineString < f64 > {
54
52
fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < Self , Box < Error + Sync + Send > > {
55
53
let path = types:: path_from_sql ( raw) ?;
56
- let points = path. points ( ) . map ( |p| Point :: new ( p. x ( ) , p. y ( ) ) ) . collect ( ) ?;
54
+ let points = path. points ( ) . map ( |p| Coordinate { x : p. x ( ) , y : p. y ( ) } ) . collect ( ) ?;
57
55
Ok ( LineString ( points) )
58
56
}
59
57
@@ -63,7 +61,7 @@ impl<'a> FromSql<'a> for LineString<f64> {
63
61
impl ToSql for LineString < f64 > {
64
62
fn to_sql ( & self , _: & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
65
63
let closed = false ; // always encode an open path from LineString
66
- types:: path_to_sql ( closed, self . 0 . iter ( ) . map ( |p| ( p. x ( ) , p. y ( ) ) ) , out) ?;
64
+ types:: path_to_sql ( closed, self . 0 . iter ( ) . map ( |p| ( p. x , p. y ) ) , out) ?;
67
65
Ok ( IsNull :: No )
68
66
}
69
67
0 commit comments