Skip to content

Commit b4ce9c3

Browse files
committed
Upgrade tokio-postgres to 2018 edition
1 parent 4d16fbb commit b4ce9c3

37 files changed

+289
-300
lines changed

tokio-postgres/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "tokio-postgres"
33
version = "0.3.0"
44
authors = ["Steven Fackler <[email protected]>"]
5+
edition = "2018"
56
license = "MIT"
67
description = "A native PostgreSQL driver using Tokio"
78
repository = "https://github.com/sfackler/rust-postgres"

tokio-postgres/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::HashMap;
22
use tokio_io::{AsyncRead, AsyncWrite};
33

4-
use proto::ConnectFuture;
5-
use {Connect, TlsMode};
4+
use crate::proto::ConnectFuture;
5+
use crate::{Connect, TlsMode};
66

77
#[derive(Clone)]
88
pub struct Builder {

tokio-postgres/src/error/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum Severity {
3232
}
3333

3434
impl fmt::Display for Severity {
35-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
35+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3636
let s = match *self {
3737
Severity::Panic => "PANIC",
3838
Severity::Fatal => "FATAL",
@@ -85,7 +85,7 @@ pub struct DbError {
8585
}
8686

8787
impl DbError {
88-
pub(crate) fn new(fields: &mut ErrorFields) -> io::Result<DbError> {
88+
pub(crate) fn new(fields: &mut ErrorFields<'_>) -> io::Result<DbError> {
8989
let mut severity = None;
9090
let mut parsed_severity = None;
9191
let mut code = None;
@@ -307,7 +307,7 @@ impl DbError {
307307
}
308308

309309
impl fmt::Display for DbError {
310-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
310+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
311311
write!(fmt, "{}: {}", self.severity, self.message)
312312
}
313313
}
@@ -348,14 +348,14 @@ enum Kind {
348348

349349
struct ErrorInner {
350350
kind: Kind,
351-
cause: Option<Box<error::Error + Sync + Send>>,
351+
cause: Option<Box<dyn error::Error + Sync + Send>>,
352352
}
353353

354354
/// An error communicating with the Postgres server.
355355
pub struct Error(Box<ErrorInner>);
356356

357357
impl fmt::Debug for Error {
358-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
358+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
359359
fmt.debug_struct("Error")
360360
.field("kind", &self.0.kind)
361361
.field("cause", &self.0.cause)
@@ -364,7 +364,7 @@ impl fmt::Debug for Error {
364364
}
365365

366366
impl fmt::Display for Error {
367-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
367+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
368368
let s = match self.0.kind {
369369
Kind::Io => "error communicating with the server",
370370
Kind::UnexpectedMessage => "unexpected message from server",
@@ -390,14 +390,14 @@ impl fmt::Display for Error {
390390
}
391391

392392
impl error::Error for Error {
393-
fn source(&self) -> Option<&(error::Error + 'static)> {
393+
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
394394
self.0.cause.as_ref().map(|e| &**e as _)
395395
}
396396
}
397397

398398
impl Error {
399399
/// Consumes the error, returning its cause.
400-
pub fn into_cause(self) -> Option<Box<error::Error + Sync + Send>> {
400+
pub fn into_cause(self) -> Option<Box<dyn error::Error + Sync + Send>> {
401401
self.0.cause
402402
}
403403

@@ -411,7 +411,7 @@ impl Error {
411411
.map(|e| e.code())
412412
}
413413

414-
fn new(kind: Kind, cause: Option<Box<error::Error + Sync + Send>>) -> Error {
414+
fn new(kind: Kind, cause: Option<Box<dyn error::Error + Sync + Send>>) -> Error {
415415
Error(Box::new(ErrorInner { kind, cause }))
416416
}
417417

@@ -438,17 +438,17 @@ impl Error {
438438
Error::new(Kind::Encode, Some(Box::new(e)))
439439
}
440440

441-
pub(crate) fn to_sql(e: Box<error::Error + Sync + Send>) -> Error {
441+
pub(crate) fn to_sql(e: Box<dyn error::Error + Sync + Send>) -> Error {
442442
Error::new(Kind::ToSql, Some(e))
443443
}
444444

445-
pub(crate) fn from_sql(e: Box<error::Error + Sync + Send>) -> Error {
445+
pub(crate) fn from_sql(e: Box<dyn error::Error + Sync + Send>) -> Error {
446446
Error::new(Kind::FromSql, Some(e))
447447
}
448448

449449
pub(crate) fn copy_in_stream<E>(e: E) -> Error
450450
where
451-
E: Into<Box<error::Error + Sync + Send>>,
451+
E: Into<Box<dyn error::Error + Sync + Send>>,
452452
{
453453
Error::new(Kind::CopyInStream, Some(e.into()))
454454
}
@@ -465,7 +465,7 @@ impl Error {
465465
Error::new(Kind::UnsupportedAuthentication, None)
466466
}
467467

468-
pub(crate) fn tls(e: Box<error::Error + Sync + Send>) -> Error {
468+
pub(crate) fn tls(e: Box<dyn error::Error + Sync + Send>) -> Error {
469469
Error::new(Kind::Tls, Some(e))
470470
}
471471

tokio-postgres/src/lib.rs

+22-32
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
1-
extern crate antidote;
2-
extern crate bytes;
3-
extern crate fallible_iterator;
4-
extern crate futures_cpupool;
5-
extern crate phf;
6-
extern crate postgres_protocol;
7-
extern crate tokio_codec;
8-
extern crate tokio_io;
9-
extern crate void;
10-
11-
#[macro_use]
12-
extern crate futures;
13-
#[macro_use]
14-
extern crate log;
15-
#[macro_use]
16-
extern crate state_machine_future;
1+
#![warn(rust_2018_idioms)]
172

183
use bytes::{Bytes, IntoBuf};
19-
use futures::{Async, Future, Poll, Stream};
4+
use futures::{try_ready, Async, Future, Poll, Stream};
205
use std::error::Error as StdError;
216
use std::fmt;
227
use std::sync::atomic::{AtomicUsize, Ordering};
238
use tokio_io::{AsyncRead, AsyncWrite};
249

25-
pub use builder::*;
26-
pub use error::*;
27-
use proto::CancelFuture;
28-
use rows::RowIndex;
29-
pub use stmt::Column;
30-
pub use tls::*;
31-
use types::{FromSql, ToSql, Type};
10+
pub use crate::builder::*;
11+
pub use crate::error::*;
12+
use crate::proto::CancelFuture;
13+
use crate::rows::RowIndex;
14+
pub use crate::stmt::Column;
15+
pub use crate::tls::*;
16+
use crate::types::{FromSql, ToSql, Type};
3217

3318
mod builder;
3419
pub mod error;
@@ -67,34 +52,39 @@ impl Client {
6752
Prepare(self.0.prepare(next_statement(), query, param_types))
6853
}
6954

70-
pub fn execute(&mut self, statement: &Statement, params: &[&ToSql]) -> Execute {
55+
pub fn execute(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Execute {
7156
Execute(self.0.execute(&statement.0, params))
7257
}
7358

74-
pub fn query(&mut self, statement: &Statement, params: &[&ToSql]) -> Query {
59+
pub fn query(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Query {
7560
Query(self.0.query(&statement.0, params))
7661
}
7762

78-
pub fn bind(&mut self, statement: &Statement, params: &[&ToSql]) -> Bind {
63+
pub fn bind(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Bind {
7964
Bind(self.0.bind(&statement.0, next_portal(), params))
8065
}
8166

8267
pub fn query_portal(&mut self, portal: &Portal, max_rows: i32) -> QueryPortal {
8368
QueryPortal(self.0.query_portal(&portal.0, max_rows))
8469
}
8570

86-
pub fn copy_in<S>(&mut self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyIn<S>
71+
pub fn copy_in<S>(
72+
&mut self,
73+
statement: &Statement,
74+
params: &[&dyn ToSql],
75+
stream: S,
76+
) -> CopyIn<S>
8777
where
8878
S: Stream,
8979
S::Item: IntoBuf,
9080
<S::Item as IntoBuf>::Buf: Send,
9181
// FIXME error type?
92-
S::Error: Into<Box<StdError + Sync + Send>>,
82+
S::Error: Into<Box<dyn StdError + Sync + Send>>,
9383
{
9484
CopyIn(self.0.copy_in(&statement.0, params, stream))
9585
}
9686

97-
pub fn copy_out(&mut self, statement: &Statement, params: &[&ToSql]) -> CopyOut {
87+
pub fn copy_out(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> CopyOut {
9888
CopyOut(self.0.copy_out(&statement.0, params))
9989
}
10090

@@ -282,14 +272,14 @@ where
282272
S: Stream,
283273
S::Item: IntoBuf,
284274
<S::Item as IntoBuf>::Buf: Send,
285-
S::Error: Into<Box<StdError + Sync + Send>>;
275+
S::Error: Into<Box<dyn StdError + Sync + Send>>;
286276

287277
impl<S> Future for CopyIn<S>
288278
where
289279
S: Stream,
290280
S::Item: IntoBuf,
291281
<S::Item as IntoBuf>::Buf: Send,
292-
S::Error: Into<Box<StdError + Sync + Send>>,
282+
S::Error: Into<Box<dyn StdError + Sync + Send>>,
293283
{
294284
type Item = u64;
295285
type Error = Error;

tokio-postgres/src/proto/bind.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use futures::sync::mpsc;
22
use futures::{Poll, Stream};
33
use postgres_protocol::message::backend::Message;
4-
use proto::client::{Client, PendingRequest};
5-
use proto::portal::Portal;
6-
use proto::statement::Statement;
7-
use state_machine_future::RentToOwn;
8-
use Error;
4+
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
5+
6+
use crate::proto::client::{Client, PendingRequest};
7+
use crate::proto::portal::Portal;
8+
use crate::proto::statement::Statement;
9+
use crate::Error;
910

1011
#[derive(StateMachineFuture)]
1112
pub enum Bind {

tokio-postgres/src/proto/cancel.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use futures::{Future, Poll};
1+
use futures::{try_ready, Future, Poll};
22
use postgres_protocol::message::frontend;
3-
use state_machine_future::RentToOwn;
3+
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
44
use tokio_io::io::{self, Flush, WriteAll};
55
use tokio_io::{AsyncRead, AsyncWrite};
66

7-
use error::Error;
8-
use proto::TlsFuture;
9-
use {CancelData, TlsMode};
7+
use crate::error::Error;
8+
use crate::proto::TlsFuture;
9+
use crate::{CancelData, TlsMode};
1010

1111
#[derive(StateMachineFuture)]
1212
pub enum Cancel<S, T>

tokio-postgres/src/proto/client.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ use std::collections::HashMap;
99
use std::error::Error as StdError;
1010
use std::sync::{Arc, Weak};
1111

12-
use proto::bind::BindFuture;
13-
use proto::connection::{Request, RequestMessages};
14-
use proto::copy_in::{CopyInFuture, CopyInReceiver, CopyMessage};
15-
use proto::copy_out::CopyOutStream;
16-
use proto::execute::ExecuteFuture;
17-
use proto::portal::Portal;
18-
use proto::prepare::PrepareFuture;
19-
use proto::query::QueryStream;
20-
use proto::simple_query::SimpleQueryFuture;
21-
use proto::statement::Statement;
22-
use types::{IsNull, Oid, ToSql, Type};
23-
use Error;
12+
use crate::proto::bind::BindFuture;
13+
use crate::proto::connection::{Request, RequestMessages};
14+
use crate::proto::copy_in::{CopyInFuture, CopyInReceiver, CopyMessage};
15+
use crate::proto::copy_out::CopyOutStream;
16+
use crate::proto::execute::ExecuteFuture;
17+
use crate::proto::portal::Portal;
18+
use crate::proto::prepare::PrepareFuture;
19+
use crate::proto::query::QueryStream;
20+
use crate::proto::simple_query::SimpleQueryFuture;
21+
use crate::proto::statement::Statement;
22+
use crate::types::{IsNull, Oid, ToSql, Type};
23+
use crate::Error;
2424

2525
pub struct PendingRequest(Result<RequestMessages, Error>);
2626

@@ -127,23 +127,23 @@ impl Client {
127127
PrepareFuture::new(self.clone(), pending, name)
128128
}
129129

130-
pub fn execute(&self, statement: &Statement, params: &[&ToSql]) -> ExecuteFuture {
130+
pub fn execute(&self, statement: &Statement, params: &[&dyn ToSql]) -> ExecuteFuture {
131131
let pending = PendingRequest(
132132
self.excecute_message(statement, params)
133133
.map(RequestMessages::Single),
134134
);
135135
ExecuteFuture::new(self.clone(), pending, statement.clone())
136136
}
137137

138-
pub fn query(&self, statement: &Statement, params: &[&ToSql]) -> QueryStream<Statement> {
138+
pub fn query(&self, statement: &Statement, params: &[&dyn ToSql]) -> QueryStream<Statement> {
139139
let pending = PendingRequest(
140140
self.excecute_message(statement, params)
141141
.map(RequestMessages::Single),
142142
);
143143
QueryStream::new(self.clone(), pending, statement.clone())
144144
}
145145

146-
pub fn bind(&self, statement: &Statement, name: String, params: &[&ToSql]) -> BindFuture {
146+
pub fn bind(&self, statement: &Statement, name: String, params: &[&dyn ToSql]) -> BindFuture {
147147
let mut buf = self.bind_message(statement, &name, params);
148148
if let Ok(ref mut buf) = buf {
149149
frontend::sync(buf);
@@ -161,12 +161,12 @@ impl Client {
161161
QueryStream::new(self.clone(), pending, portal.clone())
162162
}
163163

164-
pub fn copy_in<S>(&self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyInFuture<S>
164+
pub fn copy_in<S>(&self, statement: &Statement, params: &[&dyn ToSql], stream: S) -> CopyInFuture<S>
165165
where
166166
S: Stream,
167167
S::Item: IntoBuf,
168168
<S::Item as IntoBuf>::Buf: Send,
169-
S::Error: Into<Box<StdError + Sync + Send>>,
169+
S::Error: Into<Box<dyn StdError + Sync + Send>>,
170170
{
171171
let (mut sender, receiver) = mpsc::channel(0);
172172
let pending = PendingRequest(self.excecute_message(statement, params).map(|buf| {
@@ -182,7 +182,7 @@ impl Client {
182182
CopyInFuture::new(self.clone(), pending, statement.clone(), stream, sender)
183183
}
184184

185-
pub fn copy_out(&self, statement: &Statement, params: &[&ToSql]) -> CopyOutStream {
185+
pub fn copy_out(&self, statement: &Statement, params: &[&dyn ToSql]) -> CopyOutStream {
186186
let pending = PendingRequest(
187187
self.excecute_message(statement, params)
188188
.map(RequestMessages::Single),
@@ -213,7 +213,7 @@ impl Client {
213213
&self,
214214
statement: &Statement,
215215
name: &str,
216-
params: &[&ToSql],
216+
params: &[&dyn ToSql],
217217
) -> Result<Vec<u8>, Error> {
218218
let mut buf = vec![];
219219
let r = frontend::bind(
@@ -236,7 +236,7 @@ impl Client {
236236
}
237237
}
238238

239-
fn excecute_message(&self, statement: &Statement, params: &[&ToSql]) -> Result<Vec<u8>, Error> {
239+
fn excecute_message(&self, statement: &Statement, params: &[&dyn ToSql]) -> Result<Vec<u8>, Error> {
240240
let mut buf = self.bind_message(statement, "", params)?;
241241
frontend::execute("", 0, &mut buf).map_err(Error::parse)?;
242242
frontend::sync(&mut buf);

0 commit comments

Comments
 (0)