Config Generator
A derive macro for generating boilerplate code for a configuration struct in rust.
Installation and usage
To install this crate, add it as a dependency:
cargo add config-generator
Additionally, the serde and toml crates are required to support loading from toml.
cargo add serde toml
To use, define a struct containing configuration variable that will be loaded by the generated code. env_key annotations define an environment variable key that will be used for loading the variable from the environment.
use ConfigGenerator;
The resulting implementations will allow a config to be loaded from a toml file, the environment, or both, with loaded variables overwriting previously set ones.
// Loads a default config first from a toml file,
// then overlays environment variable values.
let config = new
.with_toml
.with_environment;
Acknowledgements
This macro is inspired by a use-case for the optional_struct macro, which also doubles as a very useful resource for those wishing to learn about writing procedural macros in rust.