mirror of https://github.com/rwf2/Rocket.git
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.
This commit is contained in:
parent
0930304aad
commit
329711db3b
|
@ -825,15 +825,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue