vc-runtime 0.1.0

Runtime backend for Visual Compiler
Documentation
//! Semantic validation: references, enabled state.

use super::{ConfigError, SemanticError};
use crate::config::model::AppConfig;

/// Validates relationships between configuration objects.
///
/// Checks:
/// - Every profile references an existing backend.
/// - Every referenced backend is enabled.
pub fn validate(config: &AppConfig) -> Result<(), ConfigError> {
    for (profile_name, profile) in &config.profiles {
        let backend =
            config.backend(&profile.backend_name).ok_or_else(|| SemanticError::UnknownBackend {
                profile: profile_name.to_owned(),
                backend: profile.backend_name.to_owned(),
            })?;

        if !backend.enabled {
            return Err(SemanticError::DisabledBackend {
                backend: profile.backend_name.to_owned(),
            }
            .into());
        }
    }
    Ok(())
}