chrony-confile 0.1.0

A full-featured Rust library for parsing, editing, validating, and serializing chrony configuration files
Documentation
//! Configuration validation.
//!
//! Provides the [`Validate`] trait and two validation passes:
//! - **Structural** ([`structural`]) -- Validates individual directive constraints
//!   (e.g. `minpoll <= maxpoll` for server directives)
//! - **Semantic** ([`semantic`]) -- Validates cross-directive constraints
//!   (e.g. matching number of `ntsservercert` and `ntsserverkey` directives)

pub mod structural;
pub mod semantic;

use crate::ast::*;
use crate::error::DirectiveError;

/// Trait for validating chrony configuration.
///
/// Implemented by [`ChronyConfig`] to run both structural and semantic validation passes.
///
/// # Examples
///
/// ```rust
/// use chrony_confile::prelude::*;
///
/// let config: ChronyConfig = "\
/// server ntp.example.com minpoll 6 maxpoll 4
/// ".parse()?;
///
/// let errors = config.validate();
///
/// // minpoll > maxpoll is a validation error
/// assert!(!errors.is_empty());
/// # Ok::<_, chrony_confile::ParseError>(())
/// ```
pub trait Validate {
    /// Validates the configuration and returns a list of errors.
    ///
    /// An empty vector indicates a valid configuration.
    fn validate(&self) -> Vec<DirectiveError>;
}

impl Validate for ChronyConfig {
    fn validate(&self) -> Vec<DirectiveError> {
        let mut errors = Vec::new();
        errors.extend(structural::validate_config(self));
        errors.extend(semantic::validate_config(self));
        errors
    }
}