Replace impl From block

This commit is contained in:
zach-com
2020-12-17 17:55:22 -05:00
parent ef95f34c34
commit 9856c7b87a
4 changed files with 6 additions and 9 deletions

View File

@@ -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(|_| ())
})
}

View File

@@ -20,9 +20,8 @@ where
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
{
type BytesResult = Result<bytes::Bytes, Error>;
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())

View File

@@ -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<Elapsed> for Error {
fn from(_e: Elapsed) -> Error {
#[doc(hidden)]
pub fn timeout() -> Error {
Error::new(Kind::Timeout, None)
}
}

View File

@@ -61,8 +61,7 @@ pub async fn query_portal(
portal: &Portal,
max_rows: i32,
) -> Result<RowStream, Error> {
type BytesResult = Result<bytes::Bytes, Error>;
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())