tier 0.1.17

Rust configuration library for layered TOML, env, and CLI settings
Documentation
use crate::ConfigMetadata;
use crate::error::ConfigError;

use super::Layer;

mod checks;
mod metadata;
mod runtime;
mod value;

use self::metadata::canonicalize_alias_overrides_against_value;
pub(super) use self::metadata::{
    canonicalize_metadata_against_layers, canonicalize_metadata_against_value,
};
use self::runtime::canonicalize_layer_path;
pub(super) use self::runtime::{
    canonicalize_runtime_path, canonicalize_runtime_path_across_layers, canonicalize_secret_paths,
    canonicalize_secret_paths_against_layers, canonicalize_secret_paths_against_value,
};
pub(super) use self::value::canonicalize_value_paths;

use self::value::canonicalize_value_paths_with_aliases;

pub(super) fn canonicalize_layer_paths(
    layer: Layer,
    metadata: &ConfigMetadata,
) -> Result<Layer, ConfigError> {
    let raw_value = layer.value;
    let aliases = canonicalize_alias_overrides_against_value(metadata, &raw_value)?;
    let value = canonicalize_value_paths_with_aliases(&raw_value, &aliases)?;

    let entries = layer
        .entries
        .into_iter()
        .map(|(path, trace)| (canonicalize_layer_path(&raw_value, &path, &aliases), trace))
        .collect();
    let coercible_string_paths = layer
        .coercible_string_paths
        .into_iter()
        .map(|path| canonicalize_layer_path(&raw_value, &path, &aliases))
        .collect();
    let indexed_array_paths = layer
        .indexed_array_paths
        .into_iter()
        .map(|path| canonicalize_layer_path(&raw_value, &path, &aliases))
        .collect();
    let indexed_array_base_lengths = layer
        .indexed_array_base_lengths
        .into_iter()
        .map(|(path, length)| (canonicalize_layer_path(&raw_value, &path, &aliases), length))
        .collect();
    let direct_array_paths = layer
        .direct_array_paths
        .into_iter()
        .map(|path| canonicalize_layer_path(&raw_value, &path, &aliases))
        .collect();

    Ok(Layer {
        trace: layer.trace,
        value,
        entries,
        coercible_string_paths,
        indexed_array_paths,
        indexed_array_base_lengths,
        direct_array_paths,
    })
}