Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support geo 0.10 #368

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

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions postgres-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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 }
22 changes: 10 additions & 12 deletions postgres-shared/src/types/geo.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
}

Expand All @@ -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))
}

Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion postgres-shared/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]

Expand All @@ -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"
10 changes: 4 additions & 6 deletions postgres/tests/types/geo.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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))",
),
Expand Down
2 changes: 1 addition & 1 deletion postgres/tests/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tokio-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]

Expand Down