mehcode/config-rs

Environment struct not loading .env file

Closed this issue · 2 comments

Using the Environment struct doesn't load environment variables in .env file

let mut environment_data: HashMap<String, String> = Config::builder()
            .add_source(Environment::default())
            .build()?.try_deserialize()?;
log::error!("Environment Data: {:?}", environment_data);

Or is there a way to only load the .env file?

This crate does not feature functionality to load .env files, just as it does not feature functionality to interpolate environment variables (which I answered in #447 (comment) already).

Also, such functionality is not planned. Use a crate like handlebars to interpolate into your configuration files! For reading .env files, I don't know whether there's a crate for that out there (I never used .env files myself, so I don't even know what format it uses).

Yes, thank you. I used handlebars and it now works

#447 (comment)