I have a configuration struct like this:
pub struct Configuration {
flag1: bool,
flag2: String,
flag3: i32,
flag4: String
}
I want to generate a configuration file template that users can edit with values. I will allow users to pass the configuration file on startup and load it to the config struct.
Is there a way to generate this artifact through some sort of annotations?
I'm imaging something similar to "serde
" but which generates the file:
#[derive(Template)] // create the file during build
pub struct Configuration {
#[template(default = true)] // set some sort of defaults for the template file
flag1: bool,
#[template(default = "yes")]
flag2: String,
#[template(default = 42)]
flag3: i32,
#[template(default = "no")]
flag4: String
}
The result will be a file like:
flag1: true
flag2: "yes"
flag3: 42
flag4: "no"