Skip to content

Commit 98f2694

Browse files
authored
Merge pull request #605 from jakubadamw/geo-types-0_5
Add support for geo-types=0.5
2 parents 9fe4eee + 887be86 commit 98f2694

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines 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_4 = ["geo-types-04"]
19+
with-geo-types-0_5 = ["geo-types-05"]
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", package = "chrono", optional = true }
3132
eui48-04 = { version = "0.4", package = "eui48", optional = true }
3233
geo-types-04 = { version = "0.4", package = "geo-types", optional = true }
34+
geo-types-05 = { version = "0.5", 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_05.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_05::{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_4")]
198198
mod geo_types_04;
199+
#[cfg(feature = "with-geo-types-0_5")]
200+
mod geo_types_05;
199201
#[cfg(feature = "with-serde_json-1")]
200202
mod serde_json_1;
201203
#[cfg(feature = "with-time-0_2")]

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_4 = ["tokio-postgres/with-geo-types-0_4"]
28+
with-geo-types-0_5 = ["tokio-postgres/with-geo-types-0_5"]
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +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 `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types) 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 |
6061
//! | `with-serde_json-1` | Enable support for the `serde_json` crate. | [serde_json](https://crates.io/crates/serde_json) 1.0 | no |
6162
//! | `with-uuid-0_8` | Enable support for the `uuid` crate. | [uuid](https://crates.io/crates/uuid) 0.8 | no |
6263
//! | `with-time-0_2` | Enable support for the `time` crate. | [time](https://crates.io/crates/time) 0.2 | no |

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_4 = ["postgres-types/with-geo-types-0_4"]
34+
with-geo-types-0_5 = ["postgres-types/with-geo-types-0_5"]
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"]
@@ -60,6 +61,7 @@ bit-vec-06 = { version = "0.6", package = "bit-vec" }
6061
chrono-04 = { version = "0.4", package = "chrono" }
6162
eui48-04 = { version = "0.4", package = "eui48" }
6263
geo-types-04 = { version = "0.4", package = "geo-types" }
64+
geo-types-05 = { version = "0.5", package = "geo-types" }
6365
serde-1 = { version = "1.0", package = "serde" }
6466
serde_json-1 = { version = "1.0", package = "serde_json" }
6567
uuid-08 = { version = "0.8", package = "uuid" }

tokio-postgres/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +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 `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types) 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 |
111112
//! | `with-serde_json-1` | Enable support for the `serde_json` crate. | [serde_json](https://crates.io/crates/serde_json) 1.0 | no |
112113
//! | `with-uuid-0_8` | Enable support for the `uuid` crate. | [uuid](https://crates.io/crates/uuid) 0.8 | no |
113114
//! | `with-time-0_2` | Enable support for the `time` crate. | [time](https://crates.io/crates/time) 0.2 | no |

0 commit comments

Comments
 (0)