config 重大改变

518521
2022/04/01 23:41:16

从 0.12 开始,config 的API发生重大改变。

以前版本

pub fn from_env() -> Result<Self, config::ConfigError> {
        let mut cfg = config::Config::new();
        cfg.merge(config::Environment::new())?;
        cfg.try_into()
    }

新版本

pub fn from_env() -> Result<Self, config::ConfigError> {
        config::Config::builder()
            .add_source(config::Environment::default())
            .build()?
            .try_deserialize()
    }

代码可见:axum-rs/v0.2.2/src/config.rs