From a6c5a7e31cb66c8e20aa2106baab7404d2ebd62d Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Mon, 4 Sep 2017 00:57:52 +0200 Subject: [PATCH] Use 'debug_struct' to improve 'Config' 'Debug' impl. Using the method `debug_struct()` of `fmt::Formatter` takes care of the exact formatting for us. Additionally, it also handles the "alternate" form of printing enabled with '#'. In the struct case it prints the struct on multiple lines instead of just one. This commit also changes the output slightly. Before, the field `log_level` was printed with `log: {}`. This commit replaces "log" with "log_level". Additionally, the value of `environment` is now printed as a struct field instead of being combined with the struct name. --- lib/src/config/config.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/config/config.rs b/lib/src/config/config.rs index 436f6505..ee52b073 100644 --- a/lib/src/config/config.rs +++ b/lib/src/config/config.rs @@ -791,15 +791,18 @@ impl Config { impl fmt::Debug for Config { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Config[{}] {{ address: {}, port: {}, workers: {}, log: {:?}", - self.environment, self.address, self.port, self.workers, - self.log_level)?; + let mut s = f.debug_struct("Config"); + s.field("environment", &self.environment); + s.field("address", &self.address); + s.field("port", &self.port); + s.field("workers", &self.workers); + s.field("log_level", &self.log_level); for (key, value) in self.extras() { - write!(f, ", {}: {}", key, value)?; + s.field(key, &value); } - write!(f, " }}") + s.finish() } }