pub fn template_for_path<S>(path: impl AsRef<Path>) -> ConfigResult<String>where
S: ConfigSchema,Expand description
Renders the default template for one path.
The template format is inferred from the path extension.
§Type Parameters
S: Config schema type used to render the template.
§Arguments
path: Output path whose extension selects the template format.
§Returns
Returns the generated template content.
§Examples
use confique::Config;
use rust_config_tree::{ConfigSchema, template_for_path};
#[derive(Config)]
struct AppConfig {
#[config(default = [])]
include: Vec<std::path::PathBuf>,
#[config(default = "demo")]
mode: String,
}
impl ConfigSchema for AppConfig {
fn include_paths(layer: &<Self as Config>::Layer) -> Vec<std::path::PathBuf> {
layer.include.clone().unwrap_or_default()
}
}
let template = template_for_path::<AppConfig>("config.yaml")?;
assert!(template.contains("mode"));