Skip to content

Commit 5dd9bb5

Browse files
TheSandwichMakrTheSandwichMakr
authored andcommitted
move Debug from Inner to Config, use Formatter::debug_struct
1 parent 4bde7d2 commit 5dd9bb5

File tree

1 file changed

+28
-40
lines changed

1 file changed

+28
-40
lines changed

tokio-postgres/src/config.rs

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,45 +69,6 @@ pub(crate) struct Inner {
6969
pub(crate) target_session_attrs: TargetSessionAttrs,
7070
}
7171

72-
// Omit password from debug output
73-
impl fmt::Debug for Inner {
74-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75-
write!(
76-
f,
77-
"Inner {{ \
78-
user: {:?}, \
79-
password: {}, \
80-
dbname: {:?}, \
81-
options: {:?}, \
82-
application_name: {:?}, \
83-
ssl_mode: {:?}, \
84-
host: {:?}, \
85-
port: {:?}, \
86-
connect_timeout: {:?}, \
87-
keepalives: {:?}, \
88-
keepalives_idle: {:?}, \
89-
target_session_attrs: {:?} \
90-
}}",
91-
self.user,
92-
if self.password.is_some() {
93-
"Some(_)"
94-
} else {
95-
"None"
96-
},
97-
self.dbname,
98-
self.options,
99-
self.application_name,
100-
self.ssl_mode,
101-
self.host,
102-
self.port,
103-
self.connect_timeout,
104-
self.keepalives,
105-
self.keepalives_idle,
106-
self.target_session_attrs
107-
)
108-
}
109-
}
110-
11172
/// Connection configuration.
11273
///
11374
/// Configuration can be parsed from libpq-style connection strings. These strings come in two formats:
@@ -181,7 +142,7 @@ impl fmt::Debug for Inner {
181142
/// ```not_rust
182143
/// postgresql:///mydb?user=user&host=/var/lib/postgresql
183144
/// ```
184-
#[derive(Debug, Clone, PartialEq)]
145+
#[derive(Clone, PartialEq)]
185146
pub struct Config(pub(crate) Arc<Inner>);
186147

187148
impl Default for Config {
@@ -453,6 +414,33 @@ impl FromStr for Config {
453414
}
454415
}
455416

417+
// Omit password from debug output
418+
impl fmt::Debug for Config {
419+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
420+
struct Redaction {}
421+
impl fmt::Debug for Redaction {
422+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
423+
write!(f, "_")
424+
}
425+
}
426+
427+
f.debug_struct("Config")
428+
.field("user", &self.0.user)
429+
.field("password", &self.0.password.as_ref().map(|_| Redaction {}))
430+
.field("dbname", &self.0.dbname)
431+
.field("options", &self.0.options)
432+
.field("application_name", &self.0.application_name)
433+
.field("ssl_mode", &self.0.ssl_mode)
434+
.field("host", &self.0.host)
435+
.field("port", &self.0.port)
436+
.field("connect_timeout", &self.0.connect_timeout)
437+
.field("keepalives", &self.0.keepalives)
438+
.field("keepalives_idle", &self.0.keepalives_idle)
439+
.field("target_session_attrs", &self.0.target_session_attrs)
440+
.finish()
441+
}
442+
}
443+
456444
#[derive(Debug)]
457445
struct UnknownOption(String);
458446

0 commit comments

Comments
 (0)