Skip to content

Commit 89ea051

Browse files
authored
Merge pull request #538 from derekdreery/add_debug_impls
Add Debug impls.
2 parents 4c0ee2c + 6fd69df commit 89ea051

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

postgres-types/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,15 @@ mod special;
207207
mod type_gen;
208208

209209
/// A Postgres type.
210-
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
210+
#[derive(PartialEq, Eq, Clone, Hash)]
211211
pub struct Type(Inner);
212212

213+
impl fmt::Debug for Type {
214+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
215+
fmt::Debug::fmt(&self.0, fmt)
216+
}
217+
}
218+
213219
impl fmt::Display for Type {
214220
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
215221
match self.schema() {

tokio-postgres/src/client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use futures::{future, pin_mut, ready, StreamExt, TryStreamExt};
2121
use parking_lot::Mutex;
2222
use postgres_protocol::message::backend::Message;
2323
use std::collections::HashMap;
24+
use std::fmt;
2425
use std::sync::Arc;
2526
use std::task::{Context, Poll};
2627
use std::time::Duration;
@@ -529,3 +530,9 @@ impl Client {
529530
self.inner.sender.is_closed()
530531
}
531532
}
533+
534+
impl fmt::Debug for Client {
535+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
536+
f.debug_struct("Client").finish()
537+
}
538+
}

tokio-postgres/src/row.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ pub struct Row {
100100
ranges: Vec<Option<Range<usize>>>,
101101
}
102102

103+
impl fmt::Debug for Row {
104+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105+
f.debug_struct("Row")
106+
.field("columns", &self.columns())
107+
.finish()
108+
}
109+
}
110+
103111
impl Row {
104112
pub(crate) fn new(statement: Statement, body: DataRowBody) -> Result<Row, Error> {
105113
let ranges = body.ranges().collect().map_err(Error::parse)?;
@@ -170,8 +178,13 @@ impl Row {
170178
));
171179
}
172180

173-
let buf = self.ranges[idx].clone().map(|r| &self.body.buffer()[r]);
174-
FromSql::from_sql_nullable(ty, buf).map_err(|e| Error::from_sql(e, idx))
181+
FromSql::from_sql_nullable(ty, self.col_buffer(idx)).map_err(|e| Error::from_sql(e, idx))
182+
}
183+
184+
/// Get the raw bytes for the column at the given index.
185+
fn col_buffer(&self, idx: usize) -> Option<&[u8]> {
186+
let range = self.ranges[idx].to_owned()?;
187+
Some(&self.body.buffer()[range])
175188
}
176189
}
177190

tokio-postgres/src/statement.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use crate::codec::FrontendMessage;
33
use crate::connection::RequestMessages;
44
use crate::types::Type;
55
use postgres_protocol::message::frontend;
6-
use std::sync::{Arc, Weak};
6+
use std::{
7+
fmt,
8+
sync::{Arc, Weak},
9+
};
710

811
struct StatementInner {
912
client: Weak<InnerClient>,
@@ -62,7 +65,6 @@ impl Statement {
6265
}
6366

6467
/// Information about a column of a query.
65-
#[derive(Debug)]
6668
pub struct Column {
6769
name: String,
6870
type_: Type,
@@ -83,3 +85,12 @@ impl Column {
8385
&self.type_
8486
}
8587
}
88+
89+
impl fmt::Debug for Column {
90+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
91+
fmt.debug_struct("Column")
92+
.field("name", &self.name)
93+
.field("type", &self.type_)
94+
.finish()
95+
}
96+
}

0 commit comments

Comments
 (0)