Skip to main content

load_config_tree

Function load_config_tree 

Source
pub fn load_config_tree<T, E, F>(
    root_path: impl AsRef<Path>,
    load: F,
) -> Result<ConfigTree<T>>
where E: Into<BoxError>, F: FnMut(&Path) -> Result<ConfigSource<T>, E>,
Expand description

Loads a config tree with default traversal options.

§Type Parameters

  • T: Loaded value type stored for each config source.
  • E: Error type returned by load.
  • F: Source loader callback type.

§Arguments

  • root_path: Root config path to load first.
  • load: Callback that receives each normalized absolute source path and returns the source value with its declared include paths.

§Returns

Returns a ConfigTree containing loaded nodes in traversal order.

§Examples

use std::{io, path::{Path, PathBuf}};
use rust_config_tree::{ConfigSource, load_config_tree};

let tree = load_config_tree(
    "root.yaml",
    |path: &Path| -> io::Result<ConfigSource<&'static str>> {
        if path.ends_with("root.yaml") {
            Ok(ConfigSource::new("root", vec![PathBuf::from("child.yaml")]))
        } else {
            Ok(ConfigSource::new("child", Vec::new()))
        }
    },
)?;

assert_eq!(tree.into_values(), vec!["root", "child"]);