Skip to content

Commit 2e61f7f

Browse files
authored
Merge pull request #734 from michaelkirk/mkirk/geo-types-0.7
Added support for `geo-types` 0.7 via `with-geo-types-0_7` feature
2 parents cc6a0ad + 8b8491f commit 2e61f7f

File tree

12 files changed

+109
-11
lines changed

12 files changed

+109
-11
lines changed

postgres-types/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Added
6+
7+
* Added support for `geo-types` 0.7 via `with-geo-types-0_7` feature.
8+
39
## v0.2.0 - 2020-12-25
410

511
### Changed

postgres-types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ with-bit-vec-0_6 = ["bit-vec-06"]
1616
with-chrono-0_4 = ["chrono-04"]
1717
with-eui48-0_4 = ["eui48-04"]
1818
with-geo-types-0_6 = ["geo-types-06"]
19+
with-geo-types-0_7 = ["geo-types-0_7"]
1920
with-serde_json-1 = ["serde-1", "serde_json-1"]
2021
with-uuid-0_8 = ["uuid-08"]
2122
with-time-0_2 = ["time-02"]
@@ -30,6 +31,7 @@ bit-vec-06 = { version = "0.6", package = "bit-vec", optional = true }
3031
chrono-04 = { version = "0.4.16", package = "chrono", default-features = false, features = ["clock"], optional = true }
3132
eui48-04 = { version = "0.4", package = "eui48", optional = true }
3233
geo-types-06 = { version = "0.6", package = "geo-types", optional = true }
34+
geo-types-0_7 = { version = "0.7", package = "geo-types", optional = true }
3335
serde-1 = { version = "1.0", package = "serde", optional = true }
3436
serde_json-1 = { version = "1.0", package = "serde_json", optional = true }
3537
uuid-08 = { version = "0.8", package = "uuid", optional = true }

postgres-types/src/geo_types_07.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use bytes::BytesMut;
2+
use fallible_iterator::FallibleIterator;
3+
use geo_types_0_7::{Coordinate, LineString, Point, Rect};
4+
use postgres_protocol::types;
5+
use std::error::Error;
6+
7+
use crate::{FromSql, IsNull, ToSql, Type};
8+
9+
impl<'a> FromSql<'a> for Point<f64> {
10+
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
11+
let point = types::point_from_sql(raw)?;
12+
Ok(Point::new(point.x(), point.y()))
13+
}
14+
15+
accepts!(POINT);
16+
}
17+
18+
impl ToSql for Point<f64> {
19+
fn to_sql(&self, _: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
20+
types::point_to_sql(self.x(), self.y(), out);
21+
Ok(IsNull::No)
22+
}
23+
24+
accepts!(POINT);
25+
to_sql_checked!();
26+
}
27+
28+
impl<'a> FromSql<'a> for Rect<f64> {
29+
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
30+
let rect = types::box_from_sql(raw)?;
31+
Ok(Rect::new(
32+
(rect.lower_left().x(), rect.lower_left().y()),
33+
(rect.upper_right().x(), rect.upper_right().y()),
34+
))
35+
}
36+
37+
accepts!(BOX);
38+
}
39+
40+
impl ToSql for Rect<f64> {
41+
fn to_sql(&self, _: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
42+
types::box_to_sql(self.min().x, self.min().y, self.max().x, self.max().y, out);
43+
Ok(IsNull::No)
44+
}
45+
46+
accepts!(BOX);
47+
to_sql_checked!();
48+
}
49+
50+
impl<'a> FromSql<'a> for LineString<f64> {
51+
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
52+
let path = types::path_from_sql(raw)?;
53+
let points = path
54+
.points()
55+
.map(|p| Ok(Coordinate { x: p.x(), y: p.y() }))
56+
.collect()?;
57+
Ok(LineString(points))
58+
}
59+
60+
accepts!(PATH);
61+
}
62+
63+
impl ToSql for LineString<f64> {
64+
fn to_sql(&self, _: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
65+
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)?;
67+
Ok(IsNull::No)
68+
}
69+
70+
accepts!(PATH);
71+
to_sql_checked!();
72+
}

postgres-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ mod chrono_04;
196196
mod eui48_04;
197197
#[cfg(feature = "with-geo-types-0_6")]
198198
mod geo_types_06;
199+
#[cfg(feature = "with-geo-types-0_7")]
200+
mod geo_types_07;
199201
#[cfg(feature = "with-serde_json-1")]
200202
mod serde_json_1;
201203
#[cfg(feature = "with-time-0_2")]

postgres/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Added
6+
7+
* Added support for `geo-types` 0.7 via `with-geo-types-0_7` feature.
8+
39
## v0.19.0 - 2020-12-25
410

511
### Changed

postgres/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ with-bit-vec-0_6 = ["tokio-postgres/with-bit-vec-0_6"]
2525
with-chrono-0_4 = ["tokio-postgres/with-chrono-0_4"]
2626
with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"]
2727
with-geo-types-0_6 = ["tokio-postgres/with-geo-types-0_6"]
28+
with-geo-types-0_7 = ["tokio-postgres/with-geo-types-0_7"]
2829
with-serde_json-1 = ["tokio-postgres/with-serde_json-1"]
2930
with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"]
3031
with-time-0_2 = ["tokio-postgres/with-time-0_2"]

postgres/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
//! | `with-bit-vec-0_6` | Enable support for the `bit-vec` crate. | [bit-vec](https://crates.io/crates/bit-vec) 0.6 | no |
5757
//! | `with-chrono-0_4` | Enable support for the `chrono` crate. | [chrono](https://crates.io/crates/chrono) 0.4 | no |
5858
//! | `with-eui48-0_4` | Enable support for the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 0.4 | no |
59-
//! | `with-geo-types-0_4` | Enable support for the 0.4 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.4.0) 0.4 | no |
60-
//! | `with-geo-types-0_5` | Enable support for the 0.5 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.5.0) 0.5 | no |
59+
//! | `with-geo-types-0_6` | Enable support for the 0.6 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.6.0) 0.6 | no |
60+
//! | `with-geo-types-0_7` | Enable support for the 0.7 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.7.0) 0.7 | no |
6161
//! | `with-serde_json-1` | Enable support for the `serde_json` crate. | [serde_json](https://crates.io/crates/serde_json) 1.0 | no |
6262
//! | `with-uuid-0_8` | Enable support for the `uuid` crate. | [uuid](https://crates.io/crates/uuid) 0.8 | no |
6363
//! | `with-time-0_2` | Enable support for the `time` crate. | [time](https://crates.io/crates/time) 0.2 | no |

tokio-postgres/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Added
6+
7+
* Added support for `geo-types` 0.7 via `with-geo-types-0_7` feature.
8+
39
## v0.7.0 - 2020-12-25
410

511
### Changed

tokio-postgres/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ with-bit-vec-0_6 = ["postgres-types/with-bit-vec-0_6"]
3131
with-chrono-0_4 = ["postgres-types/with-chrono-0_4"]
3232
with-eui48-0_4 = ["postgres-types/with-eui48-0_4"]
3333
with-geo-types-0_6 = ["postgres-types/with-geo-types-0_6"]
34+
with-geo-types-0_7 = ["postgres-types/with-geo-types-0_7"]
3435
with-serde_json-1 = ["postgres-types/with-serde_json-1"]
3536
with-uuid-0_8 = ["postgres-types/with-uuid-0_8"]
3637
with-time-0_2 = ["postgres-types/with-time-0_2"]
@@ -61,6 +62,7 @@ bit-vec-06 = { version = "0.6", package = "bit-vec" }
6162
chrono-04 = { version = "0.4", package = "chrono", default-features = false }
6263
eui48-04 = { version = "0.4", package = "eui48" }
6364
geo-types-06 = { version = "0.6", package = "geo-types" }
65+
geo-types-07 = { version = "0.7", package = "geo-types" }
6466
serde-1 = { version = "1.0", package = "serde" }
6567
serde_json-1 = { version = "1.0", package = "serde_json" }
6668
uuid-08 = { version = "0.8", package = "uuid" }

tokio-postgres/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
//! | `with-bit-vec-0_6` | Enable support for the `bit-vec` crate. | [bit-vec](https://crates.io/crates/bit-vec) 0.6 | no |
108108
//! | `with-chrono-0_4` | Enable support for the `chrono` crate. | [chrono](https://crates.io/crates/chrono) 0.4 | no |
109109
//! | `with-eui48-0_4` | Enable support for the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 0.4 | no |
110-
//! | `with-geo-types-0_4` | Enable support for the 0.4 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.4.0) 0.4 | no |
111-
//! | `with-geo-types-0_5` | Enable support for the 0.5 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.5.0) 0.5 | no |
110+
//! | `with-geo-types-0_6` | Enable support for the 0.6 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.6.0) 0.6 | no |
111+
//! | `with-geo-types-0_7` | Enable support for the 0.7 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.7.0) 0.7 | no |
112112
//! | `with-serde_json-1` | Enable support for the `serde_json` crate. | [serde_json](https://crates.io/crates/serde_json) 1.0 | no |
113113
//! | `with-uuid-0_8` | Enable support for the `uuid` crate. | [uuid](https://crates.io/crates/uuid) 0.8 | no |
114114
//! | `with-time-0_2` | Enable support for the `time` crate. | [time](https://crates.io/crates/time) 0.2 | no |

0 commit comments

Comments
 (0)