vc-runtime 0.1.0

Runtime backend for Visual Compiler
Documentation
//! Configuration loader.
//!
//! Loads `AppConfig` from TOML files with automatic validation.

use crate::config::model::AppConfig;
use crate::config::validation;
use anyhow::Result;
use std::path::Path;

/// Loads an `AppConfig` from a TOML file at the given path.
///
/// # Steps
/// 1. Reads the file.
/// 2. Parses TOML into `AppConfig`.
/// 3. Validates the configuration using `validation::validate()`.
///
/// # Errors
/// - I/O error if the file cannot be read.
/// - TOML parse error if the file is malformed.
/// - Validation error if the configuration is semantically invalid.
pub fn load_config(path: impl AsRef<Path>) -> Result<AppConfig> {
    let content = std::fs::read_to_string(path.as_ref())?;
    let config: AppConfig = toml::from_str(&content)?;
    validation::validate(&config)?;
    Ok(config)
}

#[cfg(test)]
mod tests;