mirror of https://github.com/rwf2/Rocket.git
Improve display of table config value.
This commit is contained in:
parent
90c6636821
commit
a1c4cc2224
|
@ -43,9 +43,9 @@
|
|||
//! * **session_key**: _[string]_ a 256-bit base64 encoded string (44
|
||||
//! characters) to use as the session key
|
||||
//! * example: `"8Xui8SN4mI+7egV/9dlfYYLGQJeEx4+DwmSQLwDVXJg="`
|
||||
//! * **tls**: _[dict]_ a dictionary with two keys: 1) `certs`: _[string]_ a
|
||||
//! path to a certificate chain in PEM format, and 2) `key`: _[string]_ a
|
||||
//! path to a private key file in PEM format for the certificate in `certs`
|
||||
//! * **tls**: _[table]_ a table with two keys: 1) `certs`: _[string]_ a path
|
||||
//! to a certificate chain in PEM format, and 2) `key`: _[string]_ a path to a
|
||||
//! private key file in PEM format for the certificate in `certs`
|
||||
//! * example: `{ certs = "/path/to/certs.pem", key = "/path/to/key.pem" }`
|
||||
//!
|
||||
//! ### Rocket.toml
|
||||
|
@ -196,6 +196,7 @@ pub use self::environment::Environment;
|
|||
pub use self::config::Config;
|
||||
pub use self::builder::ConfigBuilder;
|
||||
pub use self::toml_ext::IntoValue;
|
||||
pub(crate) use self::toml_ext::LoggedValue;
|
||||
|
||||
use self::Environment::*;
|
||||
use self::environment::CONFIG_ENV;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::fmt;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::hash::Hash;
|
||||
use std::str::FromStr;
|
||||
|
@ -133,6 +134,31 @@ impl_into_value!(Boolean: bool);
|
|||
impl_into_value!(Float: f64);
|
||||
impl_into_value!(Float: f32, as f64);
|
||||
|
||||
/// A simple wrapper over a `Value` reference with a custom implementation of
|
||||
/// `Display`. This is used to log config values at initialization.
|
||||
pub(crate) struct LoggedValue<'a>(pub &'a Value);
|
||||
|
||||
impl<'a> fmt::Display for LoggedValue<'a> {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use config::Value::*;
|
||||
match *self.0 {
|
||||
String(_) | Integer(_) | Float(_) | Boolean(_) | Datetime(_) | Array(_) => {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
Table(ref map) => {
|
||||
write!(f, "{{ ")?;
|
||||
for (i, (key, val)) in map.iter().enumerate() {
|
||||
write!(f, "{} = {}", key, LoggedValue(val))?;
|
||||
if i != map.len() - 1 { write!(f, ", ")?; }
|
||||
}
|
||||
|
||||
write!(f, " }}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::BTreeMap;
|
||||
|
|
|
@ -11,7 +11,7 @@ use state::Container;
|
|||
#[cfg(feature = "tls")] use hyper_rustls::TlsServer;
|
||||
use {logger, handler};
|
||||
use ext::ReadExt;
|
||||
use config::{self, Config};
|
||||
use config::{self, Config, LoggedValue};
|
||||
use request::{Request, FormItems};
|
||||
use data::Data;
|
||||
use response::{Body, Response};
|
||||
|
@ -396,7 +396,8 @@ impl Rocket {
|
|||
}
|
||||
|
||||
for (name, value) in config.extras() {
|
||||
info_!("{} {}: {}", Yellow.paint("[extra]"), name, White.paint(value));
|
||||
info_!("{} {}: {}",
|
||||
Yellow.paint("[extra]"), name, White.paint(LoggedValue(value)));
|
||||
}
|
||||
|
||||
Rocket {
|
||||
|
|
Loading…
Reference in New Issue