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
303e23f720
commit
a6c5a7e31c
|
@ -791,15 +791,18 @@ impl Config {
|
||||||
|
|
||||||
impl fmt::Debug for Config {
|
impl fmt::Debug for Config {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Config[{}] {{ address: {}, port: {}, workers: {}, log: {:?}",
|
let mut s = f.debug_struct("Config");
|
||||||
self.environment, self.address, self.port, self.workers,
|
s.field("environment", &self.environment);
|
||||||
self.log_level)?;
|
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() {
|
for (key, value) in self.extras() {
|
||||||
write!(f, ", {}: {}", key, value)?;
|
s.field(key, &value);
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, " }}")
|
s.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue