Upgrade to geo-0.10

This commit is contained in:
Artem Vorotnikov 2018-08-17 16:54:52 +03:00
parent 5ad7850009
commit a33edae15b
No known key found for this signature in database
GPG Key ID: E0148C3F2FBB7A20
7 changed files with 23 additions and 27 deletions

View File

@ -10,7 +10,7 @@ repository = "https://github.com/sfackler/rust-postgres"
"with-bit-vec-0.5" = ["bit-vec"]
"with-chrono-0.4" = ["chrono"]
"with-eui48-0.3" = ["eui48"]
"with-geo-0.8" = ["geo"]
"with-geo-0.10" = ["geo"]
with-serde_json-1 = ["serde_json"]
"with-uuid-0.6" = ["uuid"]
@ -23,6 +23,6 @@ postgres-protocol = { version = "0.3", path = "../postgres-protocol" }
bit-vec = { version = "0.5", optional = true }
chrono = { version = "0.4", optional = true }
eui48 = { version = "0.3", optional = true }
geo = { version = "0.8", optional = true }
geo = { version = "0.10", optional = true }
serde_json = { version = "1.0", optional = true }
uuid = { version = "0.6", optional = true }

View File

@ -1,6 +1,6 @@
extern crate geo;
use self::geo::{Bbox, LineString, Point};
use self::geo::{Coordinate, LineString, Point, Rect};
use fallible_iterator::FallibleIterator;
use postgres_protocol::types;
use std::error::Error;
@ -26,23 +26,21 @@ impl ToSql for Point<f64> {
to_sql_checked!();
}
impl<'a> FromSql<'a> for Bbox<f64> {
impl<'a> FromSql<'a> for Rect<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
let bbox = types::box_from_sql(raw)?;
Ok(Bbox {
xmin: bbox.lower_left().x(),
xmax: bbox.upper_right().x(),
ymin: bbox.lower_left().y(),
ymax: bbox.upper_right().y(),
let rect = types::box_from_sql(raw)?;
Ok(Rect {
min: Coordinate { x: rect.lower_left().x(), y: rect.lower_left().y(), },
max: Coordinate { x: rect.upper_right().x(), y: rect.upper_right().y(), },
})
}
accepts!(BOX);
}
impl ToSql for Bbox<f64> {
impl ToSql for Rect<f64> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
types::box_to_sql(self.xmin, self.ymin, self.xmax, self.ymax, out);
types::box_to_sql(self.min.x, self.min.y, self.max.x, self.max.y, out);
Ok(IsNull::No)
}
@ -53,7 +51,7 @@ impl ToSql for Bbox<f64> {
impl<'a> FromSql<'a> for LineString<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
let path = types::path_from_sql(raw)?;
let points = path.points().map(|p| Point::new(p.x(), p.y())).collect()?;
let points = path.points().map(|p| Coordinate { x: p.x(), y: p.y() }).collect()?;
Ok(LineString(points))
}
@ -63,7 +61,7 @@ impl<'a> FromSql<'a> for LineString<f64> {
impl ToSql for LineString<f64> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
let closed = false; // always encode an open path from LineString
types::path_to_sql(closed, self.0.iter().map(|p| (p.x(), p.y())), out)?;
types::path_to_sql(closed, self.0.iter().map(|p| (p.x, p.y)), out)?;
Ok(IsNull::No)
}

View File

@ -77,7 +77,7 @@ mod bit_vec;
mod chrono;
#[cfg(feature = "with-eui48-0.3")]
mod eui48;
#[cfg(feature = "with-geo-0.8")]
#[cfg(feature = "with-geo-0.10")]
mod geo;
#[cfg(feature = "with-serde_json-1")]
mod serde_json;

View File

@ -15,7 +15,7 @@ features = [
"with-bit-vec-0.5",
"with-chrono-0.4",
"with-eui48-0.3",
"with-geo-0.8",
"with-geo-0.10",
"with-serde_json-1",
"with-uuid-0.6",
"with-openssl",
@ -39,7 +39,7 @@ path = "tests/test.rs"
"with-bit-vec-0.5" = ["postgres-shared/with-bit-vec-0.5"]
"with-chrono-0.4" = ["postgres-shared/with-chrono-0.4"]
"with-eui48-0.3" = ["postgres-shared/with-eui48-0.3"]
"with-geo-0.8" = ["postgres-shared/with-geo-0.8"]
"with-geo-0.10" = ["postgres-shared/with-geo-0.10"]
"with-serde_json-1" = ["postgres-shared/with-serde_json-1"]
"with-uuid-0.6" = ["postgres-shared/with-uuid-0.6"]
@ -61,6 +61,6 @@ url = "1.0"
bit-vec = "0.5"
chrono = "0.4"
eui48 = "0.3"
geo = "0.8"
geo = "0.10"
serde_json = "1.0"
uuid = "0.6"

View File

@ -1,6 +1,6 @@
extern crate geo;
use self::geo::{Bbox, LineString, Point};
use self::geo::{Coordinate, LineString, Point, Rect};
use types::test_type;
#[test]
@ -21,11 +21,9 @@ fn test_box_params() {
"BOX",
&[
(
Some(Bbox {
xmax: 160.0,
ymax: 69701.5615,
xmin: -3.14,
ymin: 1.618,
Some(Rect {
min: Coordinate { x: -3.14, y: 1.618, },
max: Coordinate { x: 160.0, y: 69701.5615, },
}),
"BOX(POINT(160.0, 69701.5615), POINT(-3.14, 1.618))",
),

View File

@ -15,7 +15,7 @@ mod bit_vec;
mod chrono;
#[cfg(feature = "with-eui48-0.3")]
mod eui48;
#[cfg(feature = "with-geo-0.8")]
#[cfg(feature = "with-geo-0.10")]
mod geo;
#[cfg(feature = "with-serde_json-1")]
mod serde_json;

View File

@ -14,7 +14,7 @@ features = [
"with-bit-vec-0.5",
"with-chrono-0.4",
"with-eui48-0.3",
"with-geo-0.8",
"with-geo-0.10",
"with-serde_json-1",
"with-uuid-0.6",
"with-openssl",
@ -27,7 +27,7 @@ circle-ci = { repository = "sfackler/rust-postgres" }
"with-bit-vec-0.5" = ["postgres-shared/with-bit-vec-0.5"]
"with-chrono-0.4" = ["postgres-shared/with-chrono-0.4"]
"with-eui48-0.3" = ["postgres-shared/with-eui48-0.3"]
"with-geo-0.8" = ["postgres-shared/with-geo-0.8"]
"with-geo-0.10" = ["postgres-shared/with-geo-0.10"]
"with-serde_json-1" = ["postgres-shared/with-serde_json-1"]
"with-uuid-0.6" = ["postgres-shared/with-uuid-0.6"]