#[derive(Debug, Serialize)]
struct Args {
#[serde(rename = "database.max-connections")]
pub database_max_connections: Option<u32>,
#[serde(rename = "server.bind-address")]
pub server_bind_address: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
struct Config {
database: DatabaseConfig,
server: ServerConfig,
}
#[derive(Debug, Deserialize, Serialize)]
struct DatabaseConfig {
pub host: String,
pub port: u16,
#[serde(rename = "max-connections")]
pub max_connections: u32,
}
#[test]
fn test_override() {
let args = Args {
database_max_connections: Some(50),
server_bind_address: Some("0.0.0.0".to_string()),
};
let config = Figment::from(Serialized::defaults(Config::default()))
.merge(Serialized::from(&args, figment::Profile::Default))
.extract::<Config>();
assert_eq!(config.database.max_connections, 50);
assert_eq!(config.server.bind_address, "0.0.0.0");
}
After reading over the documentation of the Serialized provider, it seemed intuitively that it would allow you to do the following:
Expected behavior (non-functional)
After reading over data, it looks like the best immediate solution to this is instead to do:
Did I miss an easier way to accomplish this?