Skip to content

Commit 3f79a18

Browse files
committed
Use debug builders
1 parent 26f26d1 commit 3f79a18

1 file changed

Lines changed: 37 additions & 27 deletions

File tree

src/lib.rs

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
//! }
4444
//! ```
4545
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc")]
46-
#![feature(unsafe_destructor, collections, io, core, net)]
46+
#![feature(unsafe_destructor, collections, io, core, net, debug_builders)]
4747
#![cfg_attr(feature = "unix_socket", feature(path))]
4848
#![warn(missing_docs)]
4949
#![no_implicit_prelude]
@@ -259,7 +259,9 @@ pub struct Notifications<'conn> {
259259

260260
impl<'a> fmt::Debug for Notifications<'a> {
261261
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
262-
write!(fmt, "Notifications {{ pending: {} }}", self.conn.conn.borrow().notifications.len())
262+
fmt.debug_struct("Notifications")
263+
.field("pending", &self.conn.conn.borrow().notifications.len())
264+
.finish()
263265
}
264266
}
265267

@@ -882,14 +884,13 @@ pub struct Connection {
882884
impl fmt::Debug for Connection {
883885
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
884886
let conn = self.conn.borrow();
885-
write!(fmt,
886-
"Connection {{ cancel_data: {:?}, notifications: {:?}, transaction_depth: {:?}, \
887-
desynchronized: {:?}, cached_statements: {:?} }}",
888-
conn.cancel_data,
889-
conn.notifications.len(),
890-
conn.trans_depth,
891-
conn.desynchronized,
892-
conn.cached_statements.len())
887+
fmt.debug_struct("Connection")
888+
.field("cancel_data", &conn.cancel_data)
889+
.field("notifications", &conn.notifications.len())
890+
.field("transaction_depth", &conn.trans_depth)
891+
.field("desynchronized", &conn.desynchronized)
892+
.field("cached_statements", &conn.cached_statements.len())
893+
.finish()
893894
}
894895
}
895896

@@ -1196,7 +1197,10 @@ pub struct Transaction<'conn> {
11961197

11971198
impl<'a> fmt::Debug for Transaction<'a> {
11981199
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1199-
write!(fmt, "Transaction {{ commit: {:?}, depth: {:?} }}", self.commit.get(), self.depth)
1200+
fmt.debug_struct("Transaction")
1201+
.field("commit", &self.commit.get())
1202+
.field("depth", &self.depth)
1203+
.finish()
12001204
}
12011205
}
12021206

@@ -1324,11 +1328,11 @@ pub struct Statement<'conn> {
13241328

13251329
impl<'a> fmt::Debug for Statement<'a> {
13261330
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1327-
write!(fmt,
1328-
"Statement {{ name: {:?}, parameter_types: {:?}, columns: {:?} }}",
1329-
self.name,
1330-
self.param_types,
1331-
self.columns)
1331+
fmt.debug_struct("Statement")
1332+
.field("name", &self.name)
1333+
.field("parameter_types", &self.param_types)
1334+
.field("columns", &self.columns)
1335+
.finish()
13321336
}
13331337
}
13341338

@@ -1628,7 +1632,10 @@ pub struct Rows<'stmt> {
16281632

16291633
impl<'a> fmt::Debug for Rows<'a> {
16301634
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1631-
write!(fmt, "Rows {{ columns: {:?}, rows: {:?} }}", self.columns(), self.data.len())
1635+
fmt.debug_struct("Rows")
1636+
.field("columns", &self.columns())
1637+
.field("rows", &self.data.len())
1638+
.finish()
16321639
}
16331640
}
16341641

@@ -1768,7 +1775,9 @@ pub struct Row<'a> {
17681775

17691776
impl<'a> fmt::Debug for Row<'a> {
17701777
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1771-
write!(fmt, "Row {{ statement: {:?} }}", self.stmt)
1778+
fmt.debug_struct("Row")
1779+
.field("statement", self.stmt)
1780+
.finish()
17721781
}
17731782
}
17741783

@@ -1887,13 +1896,12 @@ impl<'a, 'b> Drop for LazyRows<'a, 'b> {
18871896

18881897
impl<'a, 'b> fmt::Debug for LazyRows<'a, 'b> {
18891898
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1890-
write!(fmt,
1891-
"LazyRows {{ name: {:?}, row_limit: {:?}, remaining_rows: {:?}, \
1892-
more_rows: {:?} }}",
1893-
self.name,
1894-
self.row_limit,
1895-
self.data.len(),
1896-
self.more_rows)
1899+
fmt.debug_struct("LazyRows")
1900+
.field("name", &self.name)
1901+
.field("row_limit", &self.row_limit)
1902+
.field("remaining_rows", &self.data.len())
1903+
.field("more_rows", &self.more_rows)
1904+
.finish()
18971905
}
18981906
}
18991907

@@ -1969,8 +1977,10 @@ pub struct CopyInStatement<'a> {
19691977

19701978
impl<'a> fmt::Debug for CopyInStatement<'a> {
19711979
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1972-
write!(fmt, "CopyInStatement {{ name: {:?}, column_types: {:?} }}",
1973-
self.name, self.column_types)
1980+
fmt.debug_struct("CopyInStatement")
1981+
.field("name", &self.name)
1982+
.field("column_types", &self.column_types)
1983+
.finish()
19741984
}
19751985
}
19761986

0 commit comments

Comments
 (0)