diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 0b1a0f2c..f9876e68 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -207,9 +207,15 @@ mod special; mod type_gen; /// A Postgres type. -#[derive(PartialEq, Eq, Clone, Debug, Hash)] +#[derive(PartialEq, Eq, Clone, Hash)] pub struct Type(Inner); +impl fmt::Debug for Type { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.0, fmt) + } +} + impl fmt::Display for Type { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.schema() { diff --git a/tokio-postgres/src/client.rs b/tokio-postgres/src/client.rs index 0687a08e..2d9b7972 100644 --- a/tokio-postgres/src/client.rs +++ b/tokio-postgres/src/client.rs @@ -21,6 +21,7 @@ use futures::{future, pin_mut, ready, StreamExt, TryStreamExt}; use parking_lot::Mutex; use postgres_protocol::message::backend::Message; use std::collections::HashMap; +use std::fmt; use std::sync::Arc; use std::task::{Context, Poll}; use std::time::Duration; @@ -529,3 +530,9 @@ impl Client { self.inner.sender.is_closed() } } + +impl fmt::Debug for Client { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Client").finish() + } +} diff --git a/tokio-postgres/src/row.rs b/tokio-postgres/src/row.rs index 03c7635b..842216ad 100644 --- a/tokio-postgres/src/row.rs +++ b/tokio-postgres/src/row.rs @@ -100,6 +100,14 @@ pub struct Row { ranges: Vec>>, } +impl fmt::Debug for Row { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Row") + .field("columns", &self.columns()) + .finish() + } +} + impl Row { pub(crate) fn new(statement: Statement, body: DataRowBody) -> Result { let ranges = body.ranges().collect().map_err(Error::parse)?; @@ -170,8 +178,13 @@ impl Row { )); } - let buf = self.ranges[idx].clone().map(|r| &self.body.buffer()[r]); - FromSql::from_sql_nullable(ty, buf).map_err(|e| Error::from_sql(e, idx)) + FromSql::from_sql_nullable(ty, self.col_buffer(idx)).map_err(|e| Error::from_sql(e, idx)) + } + + /// Get the raw bytes for the column at the given index. + fn col_buffer(&self, idx: usize) -> Option<&[u8]> { + let range = self.ranges[idx].to_owned()?; + Some(&self.body.buffer()[range]) } } diff --git a/tokio-postgres/src/statement.rs b/tokio-postgres/src/statement.rs index d8fa1911..97561a8e 100644 --- a/tokio-postgres/src/statement.rs +++ b/tokio-postgres/src/statement.rs @@ -3,7 +3,10 @@ use crate::codec::FrontendMessage; use crate::connection::RequestMessages; use crate::types::Type; use postgres_protocol::message::frontend; -use std::sync::{Arc, Weak}; +use std::{ + fmt, + sync::{Arc, Weak}, +}; struct StatementInner { client: Weak, @@ -62,7 +65,6 @@ impl Statement { } /// Information about a column of a query. -#[derive(Debug)] pub struct Column { name: String, type_: Type, @@ -83,3 +85,12 @@ impl Column { &self.type_ } } + +impl fmt::Debug for Column { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("Column") + .field("name", &self.name) + .field("type", &self.type_) + .finish() + } +}