diff --git a/postgres/src/client.rs b/postgres/src/client.rs index adea5e98..050c5b22 100644 --- a/postgres/src/client.rs +++ b/postgres/src/client.rs @@ -420,7 +420,8 @@ impl Client { self.connection.block_on(async { let trivial_query = inner_client.simple_query(""); tokio::time::timeout(timeout, trivial_query) - .await? + .await + .map_err(|_| Error::timeout())? .map(|_| ()) }) } diff --git a/tokio-postgres/src/bind.rs b/tokio-postgres/src/bind.rs index 75bd938d..9c5c4921 100644 --- a/tokio-postgres/src/bind.rs +++ b/tokio-postgres/src/bind.rs @@ -20,9 +20,8 @@ where I: IntoIterator, I::IntoIter: ExactSizeIterator, { - type BytesResult = Result; let name = format!("p{}", NEXT_ID.fetch_add(1, Ordering::SeqCst)); - let buf = client.with_buf::<_, BytesResult>(|buf| { + let buf = client.with_buf(|buf| { query::encode_bind(&statement, params, &name, buf)?; frontend::sync(buf); Ok(buf.split().freeze()) diff --git a/tokio-postgres/src/error/mod.rs b/tokio-postgres/src/error/mod.rs index bb0dec9a..c5383df9 100644 --- a/tokio-postgres/src/error/mod.rs +++ b/tokio-postgres/src/error/mod.rs @@ -5,7 +5,6 @@ use postgres_protocol::message::backend::{ErrorFields, ErrorResponseBody}; use std::error::{self, Error as _Error}; use std::fmt; use std::io; -use tokio::time::error::Elapsed; pub use self::sqlstate::*; @@ -494,10 +493,9 @@ impl Error { pub(crate) fn connect(e: io::Error) -> Error { Error::new(Kind::Connect, Some(Box::new(e))) } -} -impl From for Error { - fn from(_e: Elapsed) -> Error { + #[doc(hidden)] + pub fn timeout() -> Error { Error::new(Kind::Timeout, None) } } diff --git a/tokio-postgres/src/query.rs b/tokio-postgres/src/query.rs index d6179de4..f139ed91 100644 --- a/tokio-postgres/src/query.rs +++ b/tokio-postgres/src/query.rs @@ -61,8 +61,7 @@ pub async fn query_portal( portal: &Portal, max_rows: i32, ) -> Result { - type BytesResult = Result; - let buf = client.with_buf::<_, BytesResult>(|buf| { + let buf = client.with_buf(|buf| { frontend::execute(portal.name(), max_rows, buf).map_err(Error::encode)?; frontend::sync(buf); Ok(buf.split().freeze())