Environment Variables for development and production

I want to inject different sets of values with an env variable development and another set for production. is it possible in rust?

I tried this with the config crate but this is giving some errors when I directly run the .exe file in the target folder.

any suggestions?

Does #[cfg(debug_assertions)] work?

https://stackoverflow.com/questions/39204908/how-to-check-release-debug-builds-using-cfg-in-rust

Take a look at figment: https://crates.io/crates/figment. It's from the creator of the Rocket web server framework.

Invent your own, and set them yourself in your terminal/environment. There is nothing built-in into Rust.

cfg(debug_assertions) is a hack. Assertions are usually enabled in the debug mode, but they can be disabled in debug mode, and they can be also enabled in release mode.

You can use Dotenv — Rust utility // Lib.rs.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.