pub trait ConfigSchema: Config + Sized {
// Required method
fn include_paths(layer: &<Self as Config>::Layer) -> Vec<PathBuf>;
// Provided method
fn template_path_for_section(section_path: &[&str]) -> Option<PathBuf> { ... }
}Expand description
A confique schema that can expose recursive include paths and template
section layout.
Implement this trait for the same type that derives confique::Config.
include_paths receives a partially loaded layer so the crate can discover
child config files before the final schema is merged.
Required Methods§
Sourcefn include_paths(layer: &<Self as Config>::Layer) -> Vec<PathBuf>
fn include_paths(layer: &<Self as Config>::Layer) -> Vec<PathBuf>
Returns include paths declared by a loaded config layer.
Relative paths are resolved from the file that declared them. Empty paths are rejected before traversal continues.
§Arguments
layer: Partially loadedconfiquelayer for one config file.
§Returns
Returns include paths declared by layer.
§Examples
use confique::Config;
use rust_config_tree::ConfigSchema;
#[derive(Config)]
struct AppConfig {
#[config(default = [])]
include: Vec<std::path::PathBuf>,
}
impl ConfigSchema for AppConfig {
fn include_paths(layer: &<Self as Config>::Layer) -> Vec<std::path::PathBuf> {
layer.include.clone().unwrap_or_default()
}
}Provided Methods§
Sourcefn template_path_for_section(section_path: &[&str]) -> Option<PathBuf>
fn template_path_for_section(section_path: &[&str]) -> Option<PathBuf>
Overrides the generated template file path for a split nested section.
A nested section is split only when its field schema has
x-tree-split = true, for example
#[schemars(extend("x-tree-split" = true))]. By default, top-level
split sections are generated as <field>.yaml relative to the root
template directory and nested split sections as children of their
parent section file stem, e.g. trading/risk.yaml.
§Arguments
section_path: Path of nested schema field names from the root schema to the section being rendered.
§Returns
Returns Some(path) to override the generated file path, or None to
use the default section path.
§Examples
use confique::Config;
use rust_config_tree::ConfigSchema;
#[derive(Config)]
struct AppConfig {
#[config(default = [])]
include: Vec<std::path::PathBuf>,
}
impl ConfigSchema for AppConfig {
fn include_paths(layer: &<Self as Config>::Layer) -> Vec<std::path::PathBuf> {
layer.include.clone().unwrap_or_default()
}
fn template_path_for_section(section_path: &[&str]) -> Option<std::path::PathBuf> {
match section_path {
["server"] => Some(std::path::PathBuf::from("config/server.yaml")),
_ => None,
}
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.