Skip to content

Commit 99fc99b

Browse files
committed
Update to rust-postgres 0.13
1 parent 8fd01f8 commit 99fc99b

File tree

4 files changed

+48
-47
lines changed

4 files changed

+48
-47
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "postgis"
33
version = "0.2.2"
4-
authors = ["ShuYu Wang <andelf@gmail.com>"]
4+
authors = ["ShuYu Wang <andelf@gmail.com>", "Pirmin Kalberer <pka@sourcepole.ch>"]
55
description = "An extension to rust-postgres, adds support for PostGIS."
66
homepage = "https://github.com/andelf/rust-postgis"
77
repository = "https://github.com/andelf/rust-postgis"
@@ -11,5 +11,5 @@ keywords = ["PostgreSQL", "PostGIS", "GIS", "GEO"]
1111
license = "MIT"
1212

1313
[dependencies]
14-
postgres = "^0.11"
15-
byteorder = "^0.4"
14+
postgres = "^0.13"
15+
byteorder = "^0.5"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ An extension to rust-postgres, adds support for PostGIS.
1515
## Usage
1616

1717
```rust
18-
use postgres::{Connection, SslMode};
18+
use postgres::{Connection, TlsMode};
1919
use postgis::ewkb;
2020
use postgis::LineString;
2121

src/ewkb.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
//
44

55
use types as postgis;
6+
use std;
67
use std::io::prelude::*;
78
use std::mem;
89
use std::fmt;
910
use std::slice::Iter;
1011
use std::iter::FromIterator;
11-
use byteorder::{self,ReadBytesExt, WriteBytesExt, BigEndian, LittleEndian};
12+
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian, LittleEndian};
1213
use error::Error;
1314

1415
// OGC WKB specification: http://www.opengeospatial.org/standards/sfa
@@ -125,8 +126,8 @@ pub trait EwkbWrite: fmt::Debug + Sized {
125126

126127
// --- helpers
127128

128-
impl From<byteorder::Error> for Error {
129-
fn from(e: byteorder::Error) -> Error {
129+
impl From<std::io::Error> for Error {
130+
fn from(e: std::io::Error) -> Error {
130131
Error::Read(format!("error while reading: {:?}", e))
131132
}
132133
}

src/postgis.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,9 @@
55
use types::{Point, LineString, Polygon};
66
use ewkb::{self, EwkbRead, EwkbWrite, AsEwkbPoint, AsEwkbLineString, AsEwkbPolygon, AsEwkbMultiPoint, AsEwkbMultiLineString, AsEwkbMultiPolygon};
77
use twkb::{self, TwkbGeom};
8-
use std;
9-
use std::io::prelude::*;
10-
use postgres;
8+
use std::io::Cursor;
119
use postgres::types::{Type, IsNull, ToSql, FromSql, SessionInfo};
12-
use error::Error;
13-
use std::convert::From;
14-
15-
16-
impl From<Error> for postgres::error::Error {
17-
fn from(e: Error) -> postgres::error::Error {
18-
postgres::error::Error::Conversion(Box::new(e))
19-
}
20-
}
10+
use std::error::Error;
2111

2212

2313
macro_rules! accepts_geography {
@@ -36,7 +26,7 @@ macro_rules! accepts_geography {
3626
impl<'a> ToSql for ewkb::EwkbPoint<'a> {
3727
to_sql_checked!();
3828
accepts_geography!();
39-
fn to_sql<W: Write+?Sized>(&self, _: &Type, out: &mut W, _ctx: &SessionInfo) -> postgres::Result<IsNull> {
29+
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
4030
try!(self.write_ewkb(out));
4131
Ok(IsNull::No)
4232
}
@@ -46,15 +36,16 @@ macro_rules! impl_sql_for_point_type {
4636
($ptype:ident) => (
4737
impl FromSql for ewkb::$ptype {
4838
accepts_geography!();
49-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<ewkb::$ptype> {
50-
ewkb::$ptype::read_ewkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to POINT", ty).into(); postgres::error::Error::Conversion(err)})
39+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
40+
let mut rdr = Cursor::new(raw);
41+
ewkb::$ptype::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to POINT", ty).into())
5142
}
5243
}
5344

5445
impl ToSql for ewkb::$ptype {
5546
to_sql_checked!();
5647
accepts_geography!();
57-
fn to_sql<W: Write+?Sized>(&self, _: &Type, out: &mut W, _ctx: &SessionInfo) -> postgres::Result<IsNull> {
48+
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
5849
try!(self.as_ewkb().write_ewkb(out));
5950
Ok(IsNull::No)
6051
}
@@ -74,8 +65,9 @@ macro_rules! impl_sql_for_geom_type {
7465
where T: 'a + Point + EwkbRead
7566
{
7667
accepts_geography!();
77-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<ewkb::$geotype<T>> {
78-
ewkb::$geotype::<T>::read_ewkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to LINESTRING", ty).into(); postgres::error::Error::Conversion(err)})
68+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
69+
let mut rdr = Cursor::new(raw);
70+
ewkb::$geotype::<T>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to LINESTRING", ty).into())
7971
}
8072
}
8173

@@ -84,7 +76,7 @@ macro_rules! impl_sql_for_geom_type {
8476
{
8577
to_sql_checked!();
8678
accepts_geography!();
87-
fn to_sql<W: Write+?Sized>(&self, _: &Type, out: &mut W, _ctx: &SessionInfo) -> postgres::Result<IsNull> {
79+
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
8880
try!(self.as_ewkb().write_ewkb(out));
8981
Ok(IsNull::No)
9082
}
@@ -107,7 +99,7 @@ macro_rules! impl_sql_for_ewkb_type {
10799
{
108100
to_sql_checked!();
109101
accepts_geography!();
110-
fn to_sql<W: Write+?Sized>(&self, _: &Type, out: &mut W, _ctx: &SessionInfo) -> postgres::Result<IsNull> {
102+
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
111103
try!(self.write_ewkb(out));
112104
Ok(IsNull::No)
113105
}
@@ -122,7 +114,7 @@ macro_rules! impl_sql_for_ewkb_type {
122114
{
123115
to_sql_checked!();
124116
accepts_geography!();
125-
fn to_sql<W: Write+?Sized>(&self, _: &Type, out: &mut W, _ctx: &SessionInfo) -> postgres::Result<IsNull> {
117+
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
126118
try!(self.write_ewkb(out));
127119
Ok(IsNull::No)
128120
}
@@ -139,7 +131,7 @@ macro_rules! impl_sql_for_ewkb_type {
139131
{
140132
to_sql_checked!();
141133
accepts_geography!();
142-
fn to_sql<W: Write+?Sized>(&self, _: &Type, out: &mut W, _ctx: &SessionInfo) -> postgres::Result<IsNull> {
134+
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
143135
try!(self.write_ewkb(out));
144136
Ok(IsNull::No)
145137
}
@@ -158,17 +150,19 @@ impl<P> FromSql for ewkb::GeometryT<P>
158150
where P: Point + EwkbRead
159151
{
160152
accepts_geography!();
161-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<ewkb::GeometryT<P>> {
162-
ewkb::GeometryT::<P>::read_ewkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to MultiPoint", ty).into(); postgres::error::Error::Conversion(err)})
153+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
154+
let mut rdr = Cursor::new(raw);
155+
ewkb::GeometryT::<P>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiPoint", ty).into())
163156
}
164157
}
165158

166159
impl<P> FromSql for ewkb::GeometryCollectionT<P>
167160
where P: Point + EwkbRead
168161
{
169162
accepts_geography!();
170-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<ewkb::GeometryCollectionT<P>> {
171-
ewkb::GeometryCollectionT::<P>::read_ewkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to MultiPoint", ty).into(); postgres::error::Error::Conversion(err)})
163+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
164+
let mut rdr = Cursor::new(raw);
165+
ewkb::GeometryCollectionT::<P>::read_ewkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiPoint", ty).into())
172166
}
173167
}
174168

@@ -189,43 +183,49 @@ macro_rules! accepts_bytea {
189183

190184
impl FromSql for twkb::Point {
191185
accepts_bytea!();
192-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<twkb::Point> {
193-
twkb::Point::read_twkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to Point", ty).into(); postgres::error::Error::Conversion(err)})
186+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
187+
let mut rdr = Cursor::new(raw);
188+
twkb::Point::read_twkb(&mut rdr).map_err(|_| format!("cannot convert {} to Point", ty).into())
194189
}
195190
}
196191

197192
impl FromSql for twkb::LineString {
198193
accepts_bytea!();
199-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<twkb::LineString> {
200-
twkb::LineString::read_twkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to LineString", ty).into(); postgres::error::Error::Conversion(err)})
194+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
195+
let mut rdr = Cursor::new(raw);
196+
twkb::LineString::read_twkb(&mut rdr).map_err(|_| format!("cannot convert {} to LineString", ty).into())
201197
}
202198
}
203199

204200
impl FromSql for twkb::Polygon {
205201
accepts_bytea!();
206-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<twkb::Polygon> {
207-
twkb::Polygon::read_twkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to Polygon", ty).into(); postgres::error::Error::Conversion(err)})
202+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
203+
let mut rdr = Cursor::new(raw);
204+
twkb::Polygon::read_twkb(&mut rdr).map_err(|_| format!("cannot convert {} to Polygon", ty).into())
208205
}
209206
}
210207

211208
impl FromSql for twkb::MultiPoint {
212209
accepts_bytea!();
213-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<twkb::MultiPoint> {
214-
twkb::MultiPoint::read_twkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to MultiPoint", ty).into(); postgres::error::Error::Conversion(err)})
210+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
211+
let mut rdr = Cursor::new(raw);
212+
twkb::MultiPoint::read_twkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiPoint", ty).into())
215213
}
216214
}
217215

218216
impl FromSql for twkb::MultiLineString {
219217
accepts_bytea!();
220-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<twkb::MultiLineString> {
221-
twkb::MultiLineString::read_twkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to MultiLineString", ty).into(); postgres::error::Error::Conversion(err)})
218+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
219+
let mut rdr = Cursor::new(raw);
220+
twkb::MultiLineString::read_twkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiLineString", ty).into())
222221
}
223222
}
224223

225224
impl FromSql for twkb::MultiPolygon {
226225
accepts_bytea!();
227-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, _ctx: &SessionInfo) -> postgres::Result<twkb::MultiPolygon> {
228-
twkb::MultiPolygon::read_twkb(raw).map_err(|_| {let err: Box<std::error::Error + Sync + Send> = format!("cannot convert {} to MultiPolygon", ty).into(); postgres::error::Error::Conversion(err)})
226+
fn from_sql(ty: &Type, raw: &[u8], _ctx: &SessionInfo) -> Result<Self, Box<Error + Sync + Send>> {
227+
let mut rdr = Cursor::new(raw);
228+
twkb::MultiPolygon::read_twkb(&mut rdr).map_err(|_| format!("cannot convert {} to MultiPolygon", ty).into())
229229
}
230230
}
231231

@@ -251,7 +251,7 @@ mod tests {
251251

252252
fn connect() -> Connection {
253253
match env::var("DBCONN") {
254-
Result::Ok(val) => Connection::connect(&val as &str, postgres::SslMode::None),
254+
Result::Ok(val) => Connection::connect(&val as &str, postgres::TlsMode::None),
255255
Result::Err(err) => { panic!("{:#?}", err) }
256256
}.unwrap()
257257
}
@@ -543,7 +543,7 @@ mod tests {
543543
#[ignore]
544544
#[allow(unused_imports,unused_variables)]
545545
fn test_examples() {
546-
use postgres::{Connection, SslMode};
546+
use postgres::{Connection, TlsMode};
547547
//use postgis::ewkb;
548548
//use postgis::LineString;
549549

0 commit comments

Comments
 (0)