Function generate_config

Source
pub fn generate_config(
    crate_name: &str,
    config: &[ConfigOption],
    enable_unstable: bool,
    emit_md_tables: bool,
) -> HashMap<String, Value>
Expand description

Generate and parse config from a prefix, and an array of ConfigOption.

This function will parse any SCREAMING_SNAKE_CASE environment variables that match the given prefix. It will then attempt to parse the Value and run any validators which have been specified.

Stability::Unstable features will only be enabled if the unstable feature is enabled in the dependant crate. If the unstable feature is not enabled, setting these options will result in a build error.

Once the config has been parsed, this function will emit snake_case cfg’s without the prefix which can be used in the dependant crate. After that, it will create a markdown table in the OUT_DIR under the name {prefix}_config_table.md where prefix has also been converted to snake_case. This can be included in crate documentation to outline the available configuration options for the crate.

Passing a value of true for the emit_md_tables argument will create and write markdown files of the available configuration and selected configuration which can be included in documentation.

Unknown keys with the supplied prefix will cause this function to panic.