diff --git a/tokio-postgres/Cargo.toml b/tokio-postgres/Cargo.toml index 538929c7..ea8f6659 100644 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@ -2,6 +2,7 @@ name = "tokio-postgres" version = "0.3.0" authors = ["Steven Fackler "] +edition = "2018" license = "MIT" description = "A native PostgreSQL driver using Tokio" repository = "https://github.com/sfackler/rust-postgres" diff --git a/tokio-postgres/src/builder.rs b/tokio-postgres/src/builder.rs index d7436c2b..8317522a 100644 --- a/tokio-postgres/src/builder.rs +++ b/tokio-postgres/src/builder.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use tokio_io::{AsyncRead, AsyncWrite}; -use proto::ConnectFuture; -use {Connect, TlsMode}; +use crate::proto::ConnectFuture; +use crate::{Connect, TlsMode}; #[derive(Clone)] pub struct Builder { diff --git a/tokio-postgres/src/error/mod.rs b/tokio-postgres/src/error/mod.rs index bda6d402..20bb95e5 100644 --- a/tokio-postgres/src/error/mod.rs +++ b/tokio-postgres/src/error/mod.rs @@ -32,7 +32,7 @@ pub enum Severity { } impl fmt::Display for Severity { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match *self { Severity::Panic => "PANIC", Severity::Fatal => "FATAL", @@ -85,7 +85,7 @@ pub struct DbError { } impl DbError { - pub(crate) fn new(fields: &mut ErrorFields) -> io::Result { + pub(crate) fn new(fields: &mut ErrorFields<'_>) -> io::Result { let mut severity = None; let mut parsed_severity = None; let mut code = None; @@ -307,7 +307,7 @@ impl DbError { } impl fmt::Display for DbError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{}: {}", self.severity, self.message) } } @@ -348,14 +348,14 @@ enum Kind { struct ErrorInner { kind: Kind, - cause: Option>, + cause: Option>, } /// An error communicating with the Postgres server. pub struct Error(Box); impl fmt::Debug for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Error") .field("kind", &self.0.kind) .field("cause", &self.0.cause) @@ -364,7 +364,7 @@ impl fmt::Debug for Error { } impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match self.0.kind { Kind::Io => "error communicating with the server", Kind::UnexpectedMessage => "unexpected message from server", @@ -390,14 +390,14 @@ impl fmt::Display for Error { } impl error::Error for Error { - fn source(&self) -> Option<&(error::Error + 'static)> { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { self.0.cause.as_ref().map(|e| &**e as _) } } impl Error { /// Consumes the error, returning its cause. - pub fn into_cause(self) -> Option> { + pub fn into_cause(self) -> Option> { self.0.cause } @@ -411,7 +411,7 @@ impl Error { .map(|e| e.code()) } - fn new(kind: Kind, cause: Option>) -> Error { + fn new(kind: Kind, cause: Option>) -> Error { Error(Box::new(ErrorInner { kind, cause })) } @@ -438,17 +438,17 @@ impl Error { Error::new(Kind::Encode, Some(Box::new(e))) } - pub(crate) fn to_sql(e: Box) -> Error { + pub(crate) fn to_sql(e: Box) -> Error { Error::new(Kind::ToSql, Some(e)) } - pub(crate) fn from_sql(e: Box) -> Error { + pub(crate) fn from_sql(e: Box) -> Error { Error::new(Kind::FromSql, Some(e)) } pub(crate) fn copy_in_stream(e: E) -> Error where - E: Into>, + E: Into>, { Error::new(Kind::CopyInStream, Some(e.into())) } @@ -465,7 +465,7 @@ impl Error { Error::new(Kind::UnsupportedAuthentication, None) } - pub(crate) fn tls(e: Box) -> Error { + pub(crate) fn tls(e: Box) -> Error { Error::new(Kind::Tls, Some(e)) } diff --git a/tokio-postgres/src/lib.rs b/tokio-postgres/src/lib.rs index b13a47c2..83bee86a 100644 --- a/tokio-postgres/src/lib.rs +++ b/tokio-postgres/src/lib.rs @@ -1,34 +1,19 @@ -extern crate antidote; -extern crate bytes; -extern crate fallible_iterator; -extern crate futures_cpupool; -extern crate phf; -extern crate postgres_protocol; -extern crate tokio_codec; -extern crate tokio_io; -extern crate void; - -#[macro_use] -extern crate futures; -#[macro_use] -extern crate log; -#[macro_use] -extern crate state_machine_future; +#![warn(rust_2018_idioms)] use bytes::{Bytes, IntoBuf}; -use futures::{Async, Future, Poll, Stream}; +use futures::{try_ready, Async, Future, Poll, Stream}; use std::error::Error as StdError; use std::fmt; use std::sync::atomic::{AtomicUsize, Ordering}; use tokio_io::{AsyncRead, AsyncWrite}; -pub use builder::*; -pub use error::*; -use proto::CancelFuture; -use rows::RowIndex; -pub use stmt::Column; -pub use tls::*; -use types::{FromSql, ToSql, Type}; +pub use crate::builder::*; +pub use crate::error::*; +use crate::proto::CancelFuture; +use crate::rows::RowIndex; +pub use crate::stmt::Column; +pub use crate::tls::*; +use crate::types::{FromSql, ToSql, Type}; mod builder; pub mod error; @@ -67,15 +52,15 @@ impl Client { Prepare(self.0.prepare(next_statement(), query, param_types)) } - pub fn execute(&mut self, statement: &Statement, params: &[&ToSql]) -> Execute { + pub fn execute(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Execute { Execute(self.0.execute(&statement.0, params)) } - pub fn query(&mut self, statement: &Statement, params: &[&ToSql]) -> Query { + pub fn query(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Query { Query(self.0.query(&statement.0, params)) } - pub fn bind(&mut self, statement: &Statement, params: &[&ToSql]) -> Bind { + pub fn bind(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Bind { Bind(self.0.bind(&statement.0, next_portal(), params)) } @@ -83,18 +68,23 @@ impl Client { QueryPortal(self.0.query_portal(&portal.0, max_rows)) } - pub fn copy_in(&mut self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyIn + pub fn copy_in( + &mut self, + statement: &Statement, + params: &[&dyn ToSql], + stream: S, + ) -> CopyIn where S: Stream, S::Item: IntoBuf, ::Buf: Send, // FIXME error type? - S::Error: Into>, + S::Error: Into>, { CopyIn(self.0.copy_in(&statement.0, params, stream)) } - pub fn copy_out(&mut self, statement: &Statement, params: &[&ToSql]) -> CopyOut { + pub fn copy_out(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> CopyOut { CopyOut(self.0.copy_out(&statement.0, params)) } @@ -282,14 +272,14 @@ where S: Stream, S::Item: IntoBuf, ::Buf: Send, - S::Error: Into>; + S::Error: Into>; impl Future for CopyIn where S: Stream, S::Item: IntoBuf, ::Buf: Send, - S::Error: Into>, + S::Error: Into>, { type Item = u64; type Error = Error; diff --git a/tokio-postgres/src/proto/bind.rs b/tokio-postgres/src/proto/bind.rs index 00f78a0f..0a8a3b5f 100644 --- a/tokio-postgres/src/proto/bind.rs +++ b/tokio-postgres/src/proto/bind.rs @@ -1,11 +1,12 @@ use futures::sync::mpsc; use futures::{Poll, Stream}; use postgres_protocol::message::backend::Message; -use proto::client::{Client, PendingRequest}; -use proto::portal::Portal; -use proto::statement::Statement; -use state_machine_future::RentToOwn; -use Error; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; + +use crate::proto::client::{Client, PendingRequest}; +use crate::proto::portal::Portal; +use crate::proto::statement::Statement; +use crate::Error; #[derive(StateMachineFuture)] pub enum Bind { diff --git a/tokio-postgres/src/proto/cancel.rs b/tokio-postgres/src/proto/cancel.rs index 0a5e2492..dc37de65 100644 --- a/tokio-postgres/src/proto/cancel.rs +++ b/tokio-postgres/src/proto/cancel.rs @@ -1,12 +1,12 @@ -use futures::{Future, Poll}; +use futures::{try_ready, Future, Poll}; use postgres_protocol::message::frontend; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use tokio_io::io::{self, Flush, WriteAll}; use tokio_io::{AsyncRead, AsyncWrite}; -use error::Error; -use proto::TlsFuture; -use {CancelData, TlsMode}; +use crate::error::Error; +use crate::proto::TlsFuture; +use crate::{CancelData, TlsMode}; #[derive(StateMachineFuture)] pub enum Cancel diff --git a/tokio-postgres/src/proto/client.rs b/tokio-postgres/src/proto/client.rs index 60b2f709..bae395ad 100644 --- a/tokio-postgres/src/proto/client.rs +++ b/tokio-postgres/src/proto/client.rs @@ -9,18 +9,18 @@ use std::collections::HashMap; use std::error::Error as StdError; use std::sync::{Arc, Weak}; -use proto::bind::BindFuture; -use proto::connection::{Request, RequestMessages}; -use proto::copy_in::{CopyInFuture, CopyInReceiver, CopyMessage}; -use proto::copy_out::CopyOutStream; -use proto::execute::ExecuteFuture; -use proto::portal::Portal; -use proto::prepare::PrepareFuture; -use proto::query::QueryStream; -use proto::simple_query::SimpleQueryFuture; -use proto::statement::Statement; -use types::{IsNull, Oid, ToSql, Type}; -use Error; +use crate::proto::bind::BindFuture; +use crate::proto::connection::{Request, RequestMessages}; +use crate::proto::copy_in::{CopyInFuture, CopyInReceiver, CopyMessage}; +use crate::proto::copy_out::CopyOutStream; +use crate::proto::execute::ExecuteFuture; +use crate::proto::portal::Portal; +use crate::proto::prepare::PrepareFuture; +use crate::proto::query::QueryStream; +use crate::proto::simple_query::SimpleQueryFuture; +use crate::proto::statement::Statement; +use crate::types::{IsNull, Oid, ToSql, Type}; +use crate::Error; pub struct PendingRequest(Result); @@ -127,7 +127,7 @@ impl Client { PrepareFuture::new(self.clone(), pending, name) } - pub fn execute(&self, statement: &Statement, params: &[&ToSql]) -> ExecuteFuture { + pub fn execute(&self, statement: &Statement, params: &[&dyn ToSql]) -> ExecuteFuture { let pending = PendingRequest( self.excecute_message(statement, params) .map(RequestMessages::Single), @@ -135,7 +135,7 @@ impl Client { ExecuteFuture::new(self.clone(), pending, statement.clone()) } - pub fn query(&self, statement: &Statement, params: &[&ToSql]) -> QueryStream { + pub fn query(&self, statement: &Statement, params: &[&dyn ToSql]) -> QueryStream { let pending = PendingRequest( self.excecute_message(statement, params) .map(RequestMessages::Single), @@ -143,7 +143,7 @@ impl Client { QueryStream::new(self.clone(), pending, statement.clone()) } - pub fn bind(&self, statement: &Statement, name: String, params: &[&ToSql]) -> BindFuture { + pub fn bind(&self, statement: &Statement, name: String, params: &[&dyn ToSql]) -> BindFuture { let mut buf = self.bind_message(statement, &name, params); if let Ok(ref mut buf) = buf { frontend::sync(buf); @@ -161,12 +161,12 @@ impl Client { QueryStream::new(self.clone(), pending, portal.clone()) } - pub fn copy_in(&self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyInFuture + pub fn copy_in(&self, statement: &Statement, params: &[&dyn ToSql], stream: S) -> CopyInFuture where S: Stream, S::Item: IntoBuf, ::Buf: Send, - S::Error: Into>, + S::Error: Into>, { let (mut sender, receiver) = mpsc::channel(0); let pending = PendingRequest(self.excecute_message(statement, params).map(|buf| { @@ -182,7 +182,7 @@ impl Client { CopyInFuture::new(self.clone(), pending, statement.clone(), stream, sender) } - pub fn copy_out(&self, statement: &Statement, params: &[&ToSql]) -> CopyOutStream { + pub fn copy_out(&self, statement: &Statement, params: &[&dyn ToSql]) -> CopyOutStream { let pending = PendingRequest( self.excecute_message(statement, params) .map(RequestMessages::Single), @@ -213,7 +213,7 @@ impl Client { &self, statement: &Statement, name: &str, - params: &[&ToSql], + params: &[&dyn ToSql], ) -> Result, Error> { let mut buf = vec![]; let r = frontend::bind( @@ -236,7 +236,7 @@ impl Client { } } - fn excecute_message(&self, statement: &Statement, params: &[&ToSql]) -> Result, Error> { + fn excecute_message(&self, statement: &Statement, params: &[&dyn ToSql]) -> Result, Error> { let mut buf = self.bind_message(statement, "", params)?; frontend::execute("", 0, &mut buf).map_err(Error::parse)?; frontend::sync(&mut buf); diff --git a/tokio-postgres/src/proto/connect.rs b/tokio-postgres/src/proto/connect.rs index e843b593..8b5fe607 100644 --- a/tokio-postgres/src/proto/connect.rs +++ b/tokio-postgres/src/proto/connect.rs @@ -1,19 +1,19 @@ use fallible_iterator::FallibleIterator; use futures::sink; use futures::sync::mpsc; -use futures::{Future, Poll, Sink, Stream}; +use futures::{try_ready, Future, Poll, Sink, Stream}; use postgres_protocol::authentication; use postgres_protocol::authentication::sasl::{self, ScramSha256}; use postgres_protocol::message::backend::Message; use postgres_protocol::message::frontend; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use std::collections::HashMap; use std::io; use tokio_codec::Framed; use tokio_io::{AsyncRead, AsyncWrite}; -use proto::{Client, Connection, PostgresCodec, TlsFuture}; -use {CancelData, ChannelBinding, Error, TlsMode}; +use crate::proto::{Client, Connection, PostgresCodec, TlsFuture}; +use crate::{CancelData, ChannelBinding, Error, TlsMode}; #[derive(StateMachineFuture)] pub enum Connect @@ -180,7 +180,7 @@ where return Err(Error::unsupported_authentication()); }; - let mut scram = ScramSha256::new(pass.as_bytes(), channel_binding); + let scram = ScramSha256::new(pass.as_bytes(), channel_binding); let mut buf = vec![]; frontend::sasl_initial_response(mechanism, scram.message(), &mut buf) diff --git a/tokio-postgres/src/proto/connection.rs b/tokio-postgres/src/proto/connection.rs index 2f56d191..4bae09ff 100644 --- a/tokio-postgres/src/proto/connection.rs +++ b/tokio-postgres/src/proto/connection.rs @@ -1,5 +1,6 @@ use futures::sync::mpsc; -use futures::{Async, AsyncSink, Future, Poll, Sink, Stream}; +use futures::{try_ready, Async, AsyncSink, Future, Poll, Sink, Stream}; +use log::trace; use postgres_protocol::message::backend::Message; use postgres_protocol::message::frontend; use std::collections::{HashMap, VecDeque}; @@ -7,10 +8,10 @@ use std::io; use tokio_codec::Framed; use tokio_io::{AsyncRead, AsyncWrite}; -use proto::codec::PostgresCodec; -use proto::copy_in::CopyInReceiver; -use {AsyncMessage, CancelData, Notification}; -use {DbError, Error}; +use crate::proto::codec::PostgresCodec; +use crate::proto::copy_in::CopyInReceiver; +use crate::{AsyncMessage, CancelData, Notification}; +use crate::{DbError, Error}; pub enum RequestMessages { Single(Vec), diff --git a/tokio-postgres/src/proto/copy_in.rs b/tokio-postgres/src/proto/copy_in.rs index 85fbae7e..2f75596a 100644 --- a/tokio-postgres/src/proto/copy_in.rs +++ b/tokio-postgres/src/proto/copy_in.rs @@ -1,15 +1,15 @@ use bytes::{Buf, IntoBuf}; use futures::sink; use futures::sync::mpsc; -use futures::{Async, AsyncSink, Future, Poll, Sink, Stream}; +use futures::{try_ready, Async, AsyncSink, Future, Poll, Sink, Stream}; use postgres_protocol::message::backend::Message; use postgres_protocol::message::frontend; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use std::error::Error as StdError; -use proto::client::{Client, PendingRequest}; -use proto::statement::Statement; -use Error; +use crate::proto::client::{Client, PendingRequest}; +use crate::proto::statement::Statement; +use crate::Error; pub enum CopyMessage { Data(Vec), @@ -66,7 +66,7 @@ where S: Stream, S::Item: IntoBuf, ::Buf: Send, - S::Error: Into>, + S::Error: Into>, { #[state_machine_future(start, transitions(ReadCopyInResponse))] Start { @@ -107,7 +107,7 @@ where S: Stream, S::Item: IntoBuf, ::Buf: Send, - S::Error: Into>, + S::Error: Into>, { fn poll_start<'a>(state: &'a mut RentToOwn<'a, Start>) -> Poll, Error> { let state = state.take(); @@ -220,7 +220,7 @@ where S: Stream, S::Item: IntoBuf, ::Buf: Send, - S::Error: Into>, + S::Error: Into>, { pub fn new( client: Client, diff --git a/tokio-postgres/src/proto/copy_out.rs b/tokio-postgres/src/proto/copy_out.rs index 2fdf1dbf..c0418222 100644 --- a/tokio-postgres/src/proto/copy_out.rs +++ b/tokio-postgres/src/proto/copy_out.rs @@ -4,9 +4,9 @@ use futures::{Async, Poll, Stream}; use postgres_protocol::message::backend::Message; use std::mem; -use proto::client::{Client, PendingRequest}; -use proto::statement::Statement; -use Error; +use crate::proto::client::{Client, PendingRequest}; +use crate::proto::statement::Statement; +use crate::Error; enum State { Start { diff --git a/tokio-postgres/src/proto/execute.rs b/tokio-postgres/src/proto/execute.rs index 6ad3234a..25b1e90a 100644 --- a/tokio-postgres/src/proto/execute.rs +++ b/tokio-postgres/src/proto/execute.rs @@ -1,11 +1,11 @@ use futures::sync::mpsc; use futures::{Poll, Stream}; use postgres_protocol::message::backend::Message; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; -use proto::client::{Client, PendingRequest}; -use proto::statement::Statement; -use Error; +use crate::proto::client::{Client, PendingRequest}; +use crate::proto::statement::Statement; +use crate::Error; #[derive(StateMachineFuture)] pub enum Execute { diff --git a/tokio-postgres/src/proto/mod.rs b/tokio-postgres/src/proto/mod.rs index 7cf5512c..802bd6cf 100644 --- a/tokio-postgres/src/proto/mod.rs +++ b/tokio-postgres/src/proto/mod.rs @@ -13,7 +13,7 @@ macro_rules! try_ready_closed { match $e { Ok(::futures::Async::Ready(v)) => v, Ok(::futures::Async::NotReady) => return Ok(::futures::Async::NotReady), - Err(_) => return Err(::Error::closed()), + Err(_) => return Err(crate::Error::closed()), } }; } @@ -39,20 +39,20 @@ mod typeinfo; mod typeinfo_composite; mod typeinfo_enum; -pub use proto::bind::BindFuture; -pub use proto::cancel::CancelFuture; -pub use proto::client::Client; -pub use proto::codec::PostgresCodec; -pub use proto::connect::ConnectFuture; -pub use proto::connection::Connection; -pub use proto::copy_in::CopyInFuture; -pub use proto::copy_out::CopyOutStream; -pub use proto::execute::ExecuteFuture; -pub use proto::portal::Portal; -pub use proto::prepare::PrepareFuture; -pub use proto::query::QueryStream; -pub use proto::row::Row; -pub use proto::simple_query::SimpleQueryFuture; -pub use proto::statement::Statement; -pub use proto::tls::TlsFuture; -pub use proto::transaction::TransactionFuture; +pub use crate::proto::bind::BindFuture; +pub use crate::proto::cancel::CancelFuture; +pub use crate::proto::client::Client; +pub use crate::proto::codec::PostgresCodec; +pub use crate::proto::connect::ConnectFuture; +pub use crate::proto::connection::Connection; +pub use crate::proto::copy_in::CopyInFuture; +pub use crate::proto::copy_out::CopyOutStream; +pub use crate::proto::execute::ExecuteFuture; +pub use crate::proto::portal::Portal; +pub use crate::proto::prepare::PrepareFuture; +pub use crate::proto::query::QueryStream; +pub use crate::proto::row::Row; +pub use crate::proto::simple_query::SimpleQueryFuture; +pub use crate::proto::statement::Statement; +pub use crate::proto::tls::TlsFuture; +pub use crate::proto::transaction::TransactionFuture; diff --git a/tokio-postgres/src/proto/portal.rs b/tokio-postgres/src/proto/portal.rs index ef982fc5..26b93e43 100644 --- a/tokio-postgres/src/proto/portal.rs +++ b/tokio-postgres/src/proto/portal.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use proto::client::WeakClient; -use proto::statement::Statement; +use crate::proto::client::WeakClient; +use crate::proto::statement::Statement; struct Inner { client: WeakClient, diff --git a/tokio-postgres/src/proto/prepare.rs b/tokio-postgres/src/proto/prepare.rs index b4bfaaf5..368af574 100644 --- a/tokio-postgres/src/proto/prepare.rs +++ b/tokio-postgres/src/proto/prepare.rs @@ -1,16 +1,16 @@ use fallible_iterator::FallibleIterator; use futures::sync::mpsc; -use futures::{Future, Poll, Stream}; +use futures::{try_ready, Future, Poll, Stream}; use postgres_protocol::message::backend::Message; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use std::mem; use std::vec; -use proto::client::{Client, PendingRequest}; -use proto::statement::Statement; -use proto::typeinfo::TypeinfoFuture; -use types::{Oid, Type}; -use {Column, Error}; +use crate::proto::client::{Client, PendingRequest}; +use crate::proto::statement::Statement; +use crate::proto::typeinfo::TypeinfoFuture; +use crate::types::{Oid, Type}; +use crate::{Column, Error}; #[derive(StateMachineFuture)] pub enum Prepare { diff --git a/tokio-postgres/src/proto/query.rs b/tokio-postgres/src/proto/query.rs index 3cb5d137..87474eda 100644 --- a/tokio-postgres/src/proto/query.rs +++ b/tokio-postgres/src/proto/query.rs @@ -3,11 +3,11 @@ use futures::{Async, Poll, Stream}; use postgres_protocol::message::backend::Message; use std::mem; -use proto::client::{Client, PendingRequest}; -use proto::portal::Portal; -use proto::row::Row; -use proto::statement::Statement; -use Error; +use crate::proto::client::{Client, PendingRequest}; +use crate::proto::portal::Portal; +use crate::proto::row::Row; +use crate::proto::statement::Statement; +use crate::Error; pub trait StatementHolder { fn statement(&self) -> &Statement; diff --git a/tokio-postgres/src/proto/row.rs b/tokio-postgres/src/proto/row.rs index 86348f46..5fad4375 100644 --- a/tokio-postgres/src/proto/row.rs +++ b/tokio-postgres/src/proto/row.rs @@ -1,10 +1,10 @@ use postgres_protocol::message::backend::DataRowBody; use std::fmt; -use proto::statement::Statement; -use rows::{RowData, RowIndex}; -use types::{FromSql, WrongType}; -use {Column, Error}; +use crate::proto::statement::Statement; +use crate::rows::{RowData, RowIndex}; +use crate::types::{FromSql, WrongType}; +use crate::{Column, Error}; pub struct Row { statement: Statement, diff --git a/tokio-postgres/src/proto/simple_query.rs b/tokio-postgres/src/proto/simple_query.rs index e39d1b4e..d1c27930 100644 --- a/tokio-postgres/src/proto/simple_query.rs +++ b/tokio-postgres/src/proto/simple_query.rs @@ -1,10 +1,10 @@ use futures::sync::mpsc; use futures::{Poll, Stream}; use postgres_protocol::message::backend::Message; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; -use proto::client::{Client, PendingRequest}; -use Error; +use crate::proto::client::{Client, PendingRequest}; +use crate::Error; #[derive(StateMachineFuture)] pub enum SimpleQuery { diff --git a/tokio-postgres/src/proto/statement.rs b/tokio-postgres/src/proto/statement.rs index 12bee1a2..94703a48 100644 --- a/tokio-postgres/src/proto/statement.rs +++ b/tokio-postgres/src/proto/statement.rs @@ -1,8 +1,8 @@ use std::sync::Arc; -use proto::client::WeakClient; -use types::Type; -use Column; +use crate::proto::client::WeakClient; +use crate::types::Type; +use crate::Column; pub struct StatementInner { client: WeakClient, diff --git a/tokio-postgres/src/proto/tls.rs b/tokio-postgres/src/proto/tls.rs index a2439405..64a21725 100644 --- a/tokio-postgres/src/proto/tls.rs +++ b/tokio-postgres/src/proto/tls.rs @@ -1,10 +1,10 @@ -use futures::{Future, Poll}; +use futures::{try_ready, Future, Poll}; use postgres_protocol::message::frontend; -use state_machine_future::RentToOwn; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use tokio_io::io::{self, ReadExact, WriteAll}; use tokio_io::{AsyncRead, AsyncWrite}; -use {ChannelBinding, Error, TlsMode}; +use crate::{ChannelBinding, Error, TlsMode}; #[derive(StateMachineFuture)] pub enum Tls diff --git a/tokio-postgres/src/proto/transaction.rs b/tokio-postgres/src/proto/transaction.rs index 2a7b0826..fb828f78 100644 --- a/tokio-postgres/src/proto/transaction.rs +++ b/tokio-postgres/src/proto/transaction.rs @@ -1,9 +1,9 @@ -use futures::{Async, Future, Poll}; -use proto::client::Client; -use proto::simple_query::SimpleQueryFuture; -use state_machine_future::RentToOwn; +use crate::proto::client::Client; +use crate::proto::simple_query::SimpleQueryFuture; +use futures::{try_ready, Async, Future, Poll}; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; -use Error; +use crate::Error; #[derive(StateMachineFuture)] pub enum Transaction diff --git a/tokio-postgres/src/proto/typeinfo.rs b/tokio-postgres/src/proto/typeinfo.rs index 81aedcd9..78a62611 100644 --- a/tokio-postgres/src/proto/typeinfo.rs +++ b/tokio-postgres/src/proto/typeinfo.rs @@ -1,16 +1,16 @@ use futures::stream::{self, Stream}; -use futures::{Async, Future, Poll}; -use state_machine_future::RentToOwn; +use futures::{try_ready, Async, Future, Poll}; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; -use error::{Error, SqlState}; -use next_statement; -use proto::client::Client; -use proto::prepare::PrepareFuture; -use proto::query::QueryStream; -use proto::statement::Statement; -use proto::typeinfo_composite::TypeinfoCompositeFuture; -use proto::typeinfo_enum::TypeinfoEnumFuture; -use types::{Kind, Oid, Type}; +use crate::error::{Error, SqlState}; +use crate::next_statement; +use crate::proto::client::Client; +use crate::proto::prepare::PrepareFuture; +use crate::proto::query::QueryStream; +use crate::proto::statement::Statement; +use crate::proto::typeinfo_composite::TypeinfoCompositeFuture; +use crate::proto::typeinfo_enum::TypeinfoEnumFuture; +use crate::types::{Kind, Oid, Type}; const TYPEINFO_QUERY: &'static str = " SELECT t.typname, t.typtype, t.typelem, r.rngsubtype, t.typbasetype, n.nspname, t.typrelid @@ -30,10 +30,7 @@ WHERE t.oid = $1 #[derive(StateMachineFuture)] pub enum Typeinfo { - #[state_machine_future( - start, - transitions(PreparingTypeinfo, QueryingTypeinfo, Finished) - )] + #[state_machine_future(start, transitions(PreparingTypeinfo, QueryingTypeinfo, Finished))] Start { oid: Oid, client: Client }, #[state_machine_future(transitions(PreparingTypeinfoFallback, QueryingTypeinfo))] PreparingTypeinfo { @@ -136,7 +133,7 @@ impl PollTypeinfo for Typeinfo { Ok(Async::Ready(statement)) => statement, Ok(Async::NotReady) => return Ok(Async::NotReady), Err(ref e) if e.code() == Some(&SqlState::UNDEFINED_TABLE) => { - let mut state = state.take(); + let state = state.take(); transition!(PreparingTypeinfoFallback { future: Box::new(state.client.prepare( diff --git a/tokio-postgres/src/proto/typeinfo_composite.rs b/tokio-postgres/src/proto/typeinfo_composite.rs index ab2f16fb..9df260a4 100644 --- a/tokio-postgres/src/proto/typeinfo_composite.rs +++ b/tokio-postgres/src/proto/typeinfo_composite.rs @@ -1,17 +1,17 @@ use futures::stream::{self, Stream}; -use futures::{Future, Poll}; -use state_machine_future::RentToOwn; +use futures::{try_ready, Future, Poll}; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use std::mem; use std::vec; -use error::Error; -use next_statement; -use proto::client::Client; -use proto::prepare::PrepareFuture; -use proto::query::QueryStream; -use proto::statement::Statement; -use proto::typeinfo::TypeinfoFuture; -use types::{Field, Oid}; +use crate::error::Error; +use crate::next_statement; +use crate::proto::client::Client; +use crate::proto::prepare::PrepareFuture; +use crate::proto::query::QueryStream; +use crate::proto::statement::Statement; +use crate::proto::typeinfo::TypeinfoFuture; +use crate::types::{Field, Oid}; const TYPEINFO_COMPOSITE_QUERY: &'static str = " SELECT attname, atttypid @@ -99,7 +99,8 @@ impl PollTypeinfoComposite for TypeinfoComposite { let name = row.try_get(0)?.ok_or_else(Error::unexpected_message)?; let oid = row.try_get(1)?.ok_or_else(Error::unexpected_message)?; Ok((name, oid)) - }).collect::, Error>>()?; + }) + .collect::, Error>>()?; let mut remaining_fields = fields.into_iter(); match remaining_fields.next() { diff --git a/tokio-postgres/src/proto/typeinfo_enum.rs b/tokio-postgres/src/proto/typeinfo_enum.rs index 82283dbe..2f676f80 100644 --- a/tokio-postgres/src/proto/typeinfo_enum.rs +++ b/tokio-postgres/src/proto/typeinfo_enum.rs @@ -1,14 +1,14 @@ use futures::stream::{self, Stream}; -use futures::{Async, Future, Poll}; -use state_machine_future::RentToOwn; +use futures::{try_ready, Async, Future, Poll}; +use state_machine_future::{transition, RentToOwn, StateMachineFuture}; -use error::{Error, SqlState}; -use next_statement; -use proto::client::Client; -use proto::prepare::PrepareFuture; -use proto::query::QueryStream; -use proto::statement::Statement; -use types::Oid; +use crate::error::{Error, SqlState}; +use crate::next_statement; +use crate::proto::client::Client; +use crate::proto::prepare::PrepareFuture; +use crate::proto::query::QueryStream; +use crate::proto::statement::Statement; +use crate::types::Oid; const TYPEINFO_ENUM_QUERY: &'static str = " SELECT enumlabel @@ -27,10 +27,7 @@ ORDER BY oid #[derive(StateMachineFuture)] pub enum TypeinfoEnum { - #[state_machine_future( - start, - transitions(PreparingTypeinfoEnum, QueryingEnumVariants) - )] + #[state_machine_future(start, transitions(PreparingTypeinfoEnum, QueryingEnumVariants))] Start { oid: Oid, client: Client }, #[state_machine_future(transitions(PreparingTypeinfoEnumFallback, QueryingEnumVariants))] PreparingTypeinfoEnum { @@ -83,7 +80,7 @@ impl PollTypeinfoEnum for TypeinfoEnum { Ok(Async::Ready(statement)) => statement, Ok(Async::NotReady) => return Ok(Async::NotReady), Err(ref e) if e.code() == Some(&SqlState::UNDEFINED_COLUMN) => { - let mut state = state.take(); + let state = state.take(); transition!(PreparingTypeinfoEnumFallback { future: Box::new(state.client.prepare( diff --git a/tokio-postgres/src/rows.rs b/tokio-postgres/src/rows.rs index 2b0f8860..54b934b5 100644 --- a/tokio-postgres/src/rows.rs +++ b/tokio-postgres/src/rows.rs @@ -3,11 +3,11 @@ use postgres_protocol::message::backend::DataRowBody; use std::io; use std::ops::Range; -use rows::sealed::Sealed; -use stmt::Column; +use crate::rows::sealed::Sealed; +use crate::stmt::Column; mod sealed { - use stmt::Column; + use crate::stmt::Column; pub trait Sealed { fn __idx(&self, stmt: &[Column]) -> Option; diff --git a/tokio-postgres/src/stmt.rs b/tokio-postgres/src/stmt.rs index 85a993da..037706d2 100644 --- a/tokio-postgres/src/stmt.rs +++ b/tokio-postgres/src/stmt.rs @@ -1,4 +1,4 @@ -use types::Type; +use crate::types::Type; /// Information about a column of a Postgres query. #[derive(Debug)] diff --git a/tokio-postgres/src/tls.rs b/tokio-postgres/src/tls.rs index 30ea8e16..50dc8e26 100644 --- a/tokio-postgres/src/tls.rs +++ b/tokio-postgres/src/tls.rs @@ -1,6 +1,6 @@ use bytes::{Buf, BufMut}; use futures::future::{self, FutureResult}; -use futures::{Async, Future, Poll}; +use futures::{try_ready, Async, Future, Poll}; use std::error::Error; use std::fmt; use std::io::{self, Read, Write}; @@ -27,7 +27,7 @@ impl ChannelBinding { pub trait TlsMode { type Stream: AsyncRead + AsyncWrite; - type Error: Into>; + type Error: Into>; type Future: Future; fn request_tls(&self) -> bool; @@ -37,7 +37,7 @@ pub trait TlsMode { pub trait TlsConnect { type Stream: AsyncRead + AsyncWrite; - type Error: Into>; + type Error: Into>; type Future: Future; fn connect(self, stream: S) -> Self::Future; @@ -212,7 +212,7 @@ where T: TlsConnect, { type Stream = T::Stream; - type Error = Box; + type Error = Box; type Future = RequireTlsFuture; fn request_tls(&self) -> bool { @@ -234,7 +234,7 @@ where pub struct TlsUnsupportedError(()); impl fmt::Display for TlsUnsupportedError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.write_str("TLS was required but not supported by the server") } } @@ -242,18 +242,18 @@ impl fmt::Display for TlsUnsupportedError { impl Error for TlsUnsupportedError {} pub struct RequireTlsFuture { - f: Option>>, + f: Option>>, } impl Future for RequireTlsFuture where T: Future, - T::Error: Into>, + T::Error: Into>, { type Item = T::Item; - type Error = Box; + type Error = Box; - fn poll(&mut self) -> Poll> { + fn poll(&mut self) -> Poll> { match self.f.take().expect("future polled after completion") { Ok(mut f) => match f.poll().map_err(Into::into)? { Async::Ready(r) => Ok(Async::Ready(r)), diff --git a/tokio-postgres/src/types/bit_vec.rs b/tokio-postgres/src/types/bit_vec.rs index cd3f4743..5aeeae54 100644 --- a/tokio-postgres/src/types/bit_vec.rs +++ b/tokio-postgres/src/types/bit_vec.rs @@ -1,6 +1,4 @@ -extern crate bit_vec; - -use self::bit_vec::BitVec; +use bit_vec::BitVec; use postgres_protocol::types; use std::error::Error; diff --git a/tokio-postgres/src/types/chrono.rs b/tokio-postgres/src/types/chrono.rs index 2ab7da3b..5d5e7ce0 100644 --- a/tokio-postgres/src/types/chrono.rs +++ b/tokio-postgres/src/types/chrono.rs @@ -1,6 +1,4 @@ -extern crate chrono; - -use self::chrono::{ +use chrono::{ DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc, }; use postgres_protocol::types; diff --git a/tokio-postgres/src/types/eui48.rs b/tokio-postgres/src/types/eui48.rs index a4e1bb6b..37406466 100644 --- a/tokio-postgres/src/types/eui48.rs +++ b/tokio-postgres/src/types/eui48.rs @@ -1,6 +1,4 @@ -extern crate eui48; - -use self::eui48::MacAddress; +use eui48::MacAddress; use postgres_protocol::types; use std::error::Error; diff --git a/tokio-postgres/src/types/geo.rs b/tokio-postgres/src/types/geo.rs index 82f9d317..40983a2f 100644 --- a/tokio-postgres/src/types/geo.rs +++ b/tokio-postgres/src/types/geo.rs @@ -1,6 +1,4 @@ -extern crate geo; - -use self::geo::{Coordinate, LineString, Point, Rect}; +use geo::{Coordinate, LineString, Point, Rect}; use fallible_iterator::FallibleIterator; use postgres_protocol::types; use std::error::Error; diff --git a/tokio-postgres/src/types/mod.rs b/tokio-postgres/src/types/mod.rs index 9fcfef27..881a5dfc 100644 --- a/tokio-postgres/src/types/mod.rs +++ b/tokio-postgres/src/types/mod.rs @@ -10,12 +10,12 @@ use std::fmt; use std::sync::Arc; use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use types::type_gen::{Inner, Other}; +use crate::types::type_gen::{Inner, Other}; #[doc(inline)] pub use postgres_protocol::Oid; -pub use types::special::{Date, Timestamp}; +pub use crate::types::special::{Date, Timestamp}; // Number of seconds from 1970-01-01 to 2000-01-01 const TIME_SEC_CONVERSION: u64 = 946684800; @@ -46,7 +46,7 @@ macro_rules! to_sql_checked { ty: &$crate::types::Type, out: &mut ::std::vec::Vec) -> ::std::result::Result<$crate::types::IsNull, - Box<::std::error::Error + + Box> { $crate::types::__to_sql_checked(self, ty, out) @@ -61,7 +61,7 @@ pub fn __to_sql_checked( v: &T, ty: &Type, out: &mut Vec, -) -> Result> +) -> Result> where T: ToSql, { @@ -95,7 +95,7 @@ pub use self::serde_json::Json; pub struct Type(Inner); impl fmt::Display for Type { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.schema() { "public" | "pg_catalog" => {} schema => write!(fmt, "{}.", schema)?, @@ -202,7 +202,7 @@ impl Field { pub struct WasNull; impl fmt::Display for WasNull { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.write_str(self.description()) } } @@ -219,7 +219,7 @@ impl Error for WasNull { pub struct WrongType(Type); impl fmt::Display for WrongType { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!( fmt, "cannot convert to or from a Postgres value of type `{}`", @@ -301,7 +301,7 @@ pub trait FromSql<'a>: Sized { /// /// The caller of this method is responsible for ensuring that this type /// is compatible with the Postgres `Type`. - fn from_sql(ty: &Type, raw: &'a [u8]) -> Result>; + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result>; /// Creates a new value of this type from a `NULL` SQL value. /// @@ -311,7 +311,7 @@ pub trait FromSql<'a>: Sized { /// The default implementation returns /// `Err(Box::new(WasNull))`. #[allow(unused_variables)] - fn from_sql_null(ty: &Type) -> Result> { + fn from_sql_null(ty: &Type) -> Result> { Err(Box::new(WasNull)) } @@ -320,7 +320,7 @@ pub trait FromSql<'a>: Sized { fn from_sql_nullable( ty: &Type, raw: Option<&'a [u8]>, - ) -> Result> { + ) -> Result> { match raw { Some(raw) => Self::from_sql(ty, raw), None => Self::from_sql_null(ty), @@ -340,11 +340,11 @@ pub trait FromSqlOwned: for<'a> FromSql<'a> {} impl FromSqlOwned for T where T: for<'a> FromSql<'a> {} impl<'a, T: FromSql<'a>> FromSql<'a> for Option { - fn from_sql(ty: &Type, raw: &'a [u8]) -> Result, Box> { + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result, Box> { ::from_sql(ty, raw).map(Some) } - fn from_sql_null(_: &Type) -> Result, Box> { + fn from_sql_null(_: &Type) -> Result, Box> { Ok(None) } @@ -354,7 +354,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Option { } impl<'a, T: FromSql<'a>> FromSql<'a> for Vec { - fn from_sql(ty: &Type, raw: &'a [u8]) -> Result, Box> { + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result, Box> { let member_type = match *ty.kind() { Kind::Array(ref member) => member, _ => panic!("expected array type"), @@ -380,7 +380,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Vec { } impl<'a> FromSql<'a> for Vec { - fn from_sql(_: &Type, raw: &'a [u8]) -> Result, Box> { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result, Box> { Ok(types::bytea_from_sql(raw).to_owned()) } @@ -388,7 +388,7 @@ impl<'a> FromSql<'a> for Vec { } impl<'a> FromSql<'a> for &'a [u8] { - fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a [u8], Box> { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a [u8], Box> { Ok(types::bytea_from_sql(raw)) } @@ -396,7 +396,7 @@ impl<'a> FromSql<'a> for &'a [u8] { } impl<'a> FromSql<'a> for String { - fn from_sql(_: &Type, raw: &'a [u8]) -> Result> { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result> { types::text_from_sql(raw).map(|b| b.to_owned()) } @@ -406,7 +406,7 @@ impl<'a> FromSql<'a> for String { } impl<'a> FromSql<'a> for &'a str { - fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a str, Box> { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a str, Box> { types::text_from_sql(raw) } @@ -422,7 +422,7 @@ impl<'a> FromSql<'a> for &'a str { macro_rules! simple_from { ($t:ty, $f:ident, $($expected:ident),+) => { impl<'a> FromSql<'a> for $t { - fn from_sql(_: &Type, raw: &'a [u8]) -> Result<$t, Box> { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result<$t, Box> { types::$f(raw) } @@ -444,7 +444,7 @@ impl<'a> FromSql<'a> for HashMap> { fn from_sql( _: &Type, raw: &'a [u8], - ) -> Result>, Box> { + ) -> Result>, Box> { types::hstore_from_sql(raw)? .map(|(k, v)| (k.to_owned(), v.map(str::to_owned))) .collect() @@ -456,7 +456,7 @@ impl<'a> FromSql<'a> for HashMap> { } impl<'a> FromSql<'a> for SystemTime { - fn from_sql(_: &Type, raw: &'a [u8]) -> Result> { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result> { let time = types::timestamp_from_sql(raw)?; let epoch = UNIX_EPOCH + Duration::from_secs(TIME_SEC_CONVERSION); @@ -550,7 +550,7 @@ pub trait ToSql: fmt::Debug { /// The return value indicates if this value should be represented as /// `NULL`. If this is the case, implementations **must not** write /// anything to `out`. - fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> + fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> where Self: Sized; @@ -568,14 +568,14 @@ pub trait ToSql: fmt::Debug { &self, ty: &Type, out: &mut Vec, - ) -> Result>; + ) -> Result>; } impl<'a, T> ToSql for &'a T where T: ToSql, { - fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { (*self).to_sql(ty, out) } @@ -587,7 +587,7 @@ where } impl ToSql for Option { - fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { match *self { Some(ref val) => val.to_sql(ty, out), None => Ok(IsNull::Yes), @@ -602,7 +602,7 @@ impl ToSql for Option { } impl<'a, T: ToSql> ToSql for &'a [T] { - fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { let member_type = match *ty.kind() { Kind::Array(ref member) => member, _ => panic!("expected array type"), @@ -637,7 +637,7 @@ impl<'a, T: ToSql> ToSql for &'a [T] { } impl<'a> ToSql for &'a [u8] { - fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { types::bytea_to_sql(*self, w); Ok(IsNull::No) } @@ -648,7 +648,7 @@ impl<'a> ToSql for &'a [u8] { } impl ToSql for Vec { - fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { <&[T] as ToSql>::to_sql(&&**self, ty, w) } @@ -660,7 +660,7 @@ impl ToSql for Vec { } impl ToSql for Vec { - fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { <&[u8] as ToSql>::to_sql(&&**self, ty, w) } @@ -672,7 +672,7 @@ impl ToSql for Vec { } impl<'a> ToSql for &'a str { - fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { types::text_to_sql(*self, w); Ok(IsNull::No) } @@ -689,7 +689,7 @@ impl<'a> ToSql for &'a str { } impl<'a> ToSql for Cow<'a, str> { - fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { <&str as ToSql>::to_sql(&&self.as_ref(), ty, w) } @@ -701,7 +701,7 @@ impl<'a> ToSql for Cow<'a, str> { } impl ToSql for String { - fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { <&str as ToSql>::to_sql(&&**self, ty, w) } @@ -718,7 +718,7 @@ macro_rules! simple_to { fn to_sql(&self, _: &Type, w: &mut Vec) - -> Result> { + -> Result> { types::$f(*self, w); Ok(IsNull::No) } @@ -740,7 +740,7 @@ simple_to!(f32, float4_to_sql, FLOAT4); simple_to!(f64, float8_to_sql, FLOAT8); impl ToSql for HashMap> { - fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { types::hstore_to_sql( self.iter().map(|(k, v)| (&**k, v.as_ref().map(|v| &**v))), w, @@ -756,7 +756,7 @@ impl ToSql for HashMap> { } impl ToSql for SystemTime { - fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { + fn to_sql(&self, _: &Type, w: &mut Vec) -> Result> { let epoch = UNIX_EPOCH + Duration::from_secs(TIME_SEC_CONVERSION); let to_usec = @@ -776,7 +776,7 @@ impl ToSql for SystemTime { to_sql_checked!(); } -fn downcast(len: usize) -> Result> { +fn downcast(len: usize) -> Result> { if len > i32::max_value() as usize { Err("value too large to transmit".into()) } else { diff --git a/tokio-postgres/src/types/serde_json.rs b/tokio-postgres/src/types/serde_json.rs index 9544f6d2..0b933830 100644 --- a/tokio-postgres/src/types/serde_json.rs +++ b/tokio-postgres/src/types/serde_json.rs @@ -1,8 +1,5 @@ -extern crate serde; -extern crate serde_json; - -use self::serde::{Deserialize, Serialize}; -use self::serde_json::Value; +use serde::{Deserialize, Serialize}; +use serde_json::Value; use std::error::Error; use std::fmt::Debug; use std::io::Read; diff --git a/tokio-postgres/src/types/special.rs b/tokio-postgres/src/types/special.rs index a0566319..15538f7a 100644 --- a/tokio-postgres/src/types/special.rs +++ b/tokio-postgres/src/types/special.rs @@ -2,7 +2,7 @@ use postgres_protocol::types; use std::error::Error; use std::{i32, i64}; -use types::{FromSql, IsNull, ToSql, Type}; +use crate::types::{FromSql, IsNull, ToSql, Type}; /// A wrapper that can be used to represent infinity with `Type::Date` types. #[derive(Debug, Clone, Copy, PartialEq)] @@ -16,7 +16,7 @@ pub enum Date { } impl<'a, T: FromSql<'a>> FromSql<'a> for Date { - fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { match types::date_from_sql(raw)? { i32::MAX => Ok(Date::PosInfinity), i32::MIN => Ok(Date::NegInfinity), @@ -30,7 +30,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Date { } impl ToSql for Date { - fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { let value = match *self { Date::PosInfinity => i32::MAX, Date::NegInfinity => i32::MIN, @@ -61,7 +61,7 @@ pub enum Timestamp { } impl<'a, T: FromSql<'a>> FromSql<'a> for Timestamp { - fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { match types::timestamp_from_sql(raw)? { i64::MAX => Ok(Timestamp::PosInfinity), i64::MIN => Ok(Timestamp::NegInfinity), @@ -78,7 +78,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Timestamp { } impl ToSql for Timestamp { - fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { + fn to_sql(&self, ty: &Type, out: &mut Vec) -> Result> { let value = match *self { Timestamp::PosInfinity => i64::MAX, Timestamp::NegInfinity => i64::MIN, diff --git a/tokio-postgres/src/types/type_gen.rs b/tokio-postgres/src/types/type_gen.rs index 4ce0c5fb..7dd28f42 100644 --- a/tokio-postgres/src/types/type_gen.rs +++ b/tokio-postgres/src/types/type_gen.rs @@ -1,7 +1,7 @@ // Autogenerated file - DO NOT EDIT use std::sync::Arc; -use types::{Kind, Oid, Type}; +use crate::types::{Kind, Oid, Type}; #[derive(PartialEq, Eq, Debug)] pub struct Other { diff --git a/tokio-postgres/src/types/uuid.rs b/tokio-postgres/src/types/uuid.rs index d7a190d0..2e34d01c 100644 --- a/tokio-postgres/src/types/uuid.rs +++ b/tokio-postgres/src/types/uuid.rs @@ -1,6 +1,4 @@ -extern crate uuid; - -use self::uuid::Uuid; +use uuid::Uuid; use postgres_protocol::types; use std::error::Error; diff --git a/tokio-postgres/tests/test.rs b/tokio-postgres/tests/test.rs index 6efa2ddc..06d85d64 100644 --- a/tokio-postgres/tests/test.rs +++ b/tokio-postgres/tests/test.rs @@ -1,15 +1,8 @@ -extern crate env_logger; -extern crate tokio; -extern crate tokio_postgres; +#![warn(rust_2018_idioms)] -#[macro_use] -extern crate futures; -#[macro_use] -extern crate log; - -use futures::future; -use futures::stream; use futures::sync::mpsc; +use futures::{future, stream, try_ready}; +use log::debug; use std::error::Error; use std::time::{Duration, Instant}; use tokio::net::TcpStream; @@ -244,7 +237,8 @@ fn query_portal() { "CREATE TEMPORARY TABLE foo (id SERIAL, name TEXT); INSERT INTO foo (name) VALUES ('alice'), ('bob'), ('charlie'); BEGIN;", - )).unwrap(); + )) + .unwrap(); let statement = runtime .block_on(client.prepare("SELECT id, name FROM foo ORDER BY id")) @@ -292,10 +286,12 @@ fn cancel_query() { .then(|r| { r.unwrap(); TcpStream::connect(&"127.0.0.1:5433".parse().unwrap()) - }).then(|r| { + }) + .then(|r| { let s = r.unwrap(); tokio_postgres::cancel_query(s, NoTls, cancel_data) - }).then(|r| { + }) + .then(|r| { r.unwrap(); Ok::<(), ()>(()) }); @@ -321,7 +317,8 @@ fn custom_enum() { 'ok', 'happy' )", - )).unwrap(); + )) + .unwrap(); let select = client.prepare("SELECT $1::mood"); let select = runtime.block_on(select).unwrap(); @@ -352,7 +349,8 @@ fn custom_domain() { runtime .block_on(client.batch_execute( "CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16)", - )).unwrap(); + )) + .unwrap(); let select = client.prepare("SELECT $1::session_id"); let select = runtime.block_on(select).unwrap(); @@ -405,7 +403,8 @@ fn custom_composite() { supplier INTEGER, price NUMERIC )", - )).unwrap(); + )) + .unwrap(); let select = client.prepare("SELECT $1::inventory_item"); let select = runtime.block_on(select).unwrap(); @@ -442,7 +441,8 @@ fn custom_range() { subtype = float8, subtype_diff = float8mi )", - )).unwrap(); + )) + .unwrap(); let select = client.prepare("SELECT $1::floatrange"); let select = runtime.block_on(select).unwrap(); @@ -534,7 +534,8 @@ fn transaction_commit() { id SERIAL, name TEXT )", - )).unwrap(); + )) + .unwrap(); let f = client.batch_execute("INSERT INTO foo (name) VALUES ('steven')"); runtime.block_on(client.transaction().build(f)).unwrap(); @@ -544,7 +545,8 @@ fn transaction_commit() { client .prepare("SELECT name FROM foo") .and_then(|s| client.query(&s, &[]).collect()), - ).unwrap(); + ) + .unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::<_, &str>(0), "steven"); @@ -567,12 +569,13 @@ fn transaction_abort() { id SERIAL, name TEXT )", - )).unwrap(); + )) + .unwrap(); let f = client .batch_execute("INSERT INTO foo (name) VALUES ('steven')") - .map_err(|e| Box::new(e) as Box) - .and_then(|_| Err::<(), _>(Box::::from(""))); + .map_err(|e| Box::new(e) as Box) + .and_then(|_| Err::<(), _>(Box::::from(""))); runtime.block_on(client.transaction().build(f)).unwrap_err(); let rows = runtime @@ -580,7 +583,8 @@ fn transaction_abort() { client .prepare("SELECT name FROM foo") .and_then(|s| client.query(&s, &[]).collect()), - ).unwrap(); + ) + .unwrap(); assert_eq!(rows.len(), 0); } @@ -602,7 +606,8 @@ fn copy_in() { id INTEGER, name TEXT )", - )).unwrap(); + )) + .unwrap(); let stream = stream::iter_ok::<_, String>(vec![b"1\tjim\n".to_vec(), b"2\tjoe\n".to_vec()]); let rows = runtime @@ -610,7 +615,8 @@ fn copy_in() { client .prepare("COPY foo FROM STDIN") .and_then(|s| client.copy_in(&s, &[], stream)), - ).unwrap(); + ) + .unwrap(); assert_eq!(rows, 2); let rows = runtime @@ -618,7 +624,8 @@ fn copy_in() { client .prepare("SELECT id, name FROM foo ORDER BY id") .and_then(|s| client.query(&s, &[]).collect()), - ).unwrap(); + ) + .unwrap(); assert_eq!(rows.len(), 2); assert_eq!(rows[0].get::<_, i32>(0), 1); @@ -644,7 +651,8 @@ fn copy_in_error() { id INTEGER, name TEXT )", - )).unwrap(); + )) + .unwrap(); let stream = stream::iter_result(vec![Ok(b"1\tjim\n".to_vec()), Err("asdf")]); let error = runtime @@ -652,7 +660,8 @@ fn copy_in_error() { client .prepare("COPY foo FROM STDIN") .and_then(|s| client.copy_in(&s, &[], stream)), - ).unwrap_err(); + ) + .unwrap_err(); assert!(error.to_string().contains("asdf")); let rows = runtime @@ -660,7 +669,8 @@ fn copy_in_error() { client .prepare("SELECT id, name FROM foo ORDER BY id") .and_then(|s| client.query(&s, &[]).collect()), - ).unwrap(); + ) + .unwrap(); assert_eq!(rows.len(), 0); } @@ -683,14 +693,16 @@ fn copy_out() { name TEXT ); INSERT INTO foo (name) VALUES ('jim'), ('joe');", - )).unwrap(); + )) + .unwrap(); let data = runtime .block_on( client .prepare("COPY foo TO STDOUT") .and_then(|s| client.copy_out(&s, &[]).concat2()), - ).unwrap(); + ) + .unwrap(); assert_eq!(&data[..], b"1\tjim\n2\tjoe\n"); } @@ -719,7 +731,8 @@ fn transaction_builder_around_moved_client() { .prepare("INSERT INTO transaction_foo (name) VALUES ($1), ($2)") .map(|statement| (client, statement)) }) - }).and_then(|(mut client, statement)| { + }) + .and_then(|(mut client, statement)| { client .query(&statement, &[&"jim", &"joe"]) .collect() @@ -734,7 +747,8 @@ fn transaction_builder_around_moved_client() { client .prepare("COPY transaction_foo TO STDOUT") .and_then(|s| client.copy_out(&s, &[]).concat2()), - ).unwrap(); + ) + .unwrap(); assert_eq!(&data[..], b"1\tjim\n2\tjoe\n"); drop(client);