configbuilder-pattern-validator 0.1.0

configbuilder-pattern: validator domain, trait contract + tech-agnostic reference implementation.
Documentation
use crate::{Validator, ValidatorError, ValidatorOps};

/// Reference `Validator` implementation: a generic dispatch shell over any real
/// [`ValidatorOps`] implementor.
///
/// Doesn't care what's boxed inside -- the real, filesystem-backed implementor
/// (`configbuilder-svc-validator-spi`) is constructed by
/// `configbuilder-svc-saf` and boxed here.
pub struct DefaultValidator {
    /// The real `ValidatorOps` implementor this validator dispatches to.
    pub ops: Box<dyn ValidatorOps>,
}

impl DefaultValidator {
    /// Validate a filesystem path using the configured validator, returning
    /// [`configbuilder_pattern_loader::ConfigError`] directly for callers already
    /// working in that error type (e.g. `configbuilder-svc-saf`'s
    /// composition root). External consumers should prefer the [`Validator`] trait
    /// impl below, which returns [`ValidatorError`].
    pub fn validate_path(
        &self,
        target: &std::path::Path,
    ) -> Result<(), configbuilder_pattern_loader::ConfigError> {
        self.ops
            .check_path(target)
            .map_err(configbuilder_pattern_loader::ConfigError::from)
    }
}

impl Validator for DefaultValidator {
    fn validate_path(&self, target: &std::path::Path) -> Result<(), ValidatorError> {
        self.ops.check_path(target)
    }
}