configbuilder_pattern_validator/default_validator.rs
1use crate::{Validator, ValidatorError, ValidatorOps};
2
3/// Reference `Validator` implementation: a generic dispatch shell over any real
4/// [`ValidatorOps`] implementor.
5///
6/// Doesn't care what's boxed inside -- the real, filesystem-backed implementor
7/// (`configbuilder-svc-validator-spi`) is constructed by
8/// `configbuilder-svc-saf` and boxed here.
9pub struct DefaultValidator {
10 /// The real `ValidatorOps` implementor this validator dispatches to.
11 pub ops: Box<dyn ValidatorOps>,
12}
13
14impl DefaultValidator {
15 /// Validate a filesystem path using the configured validator, returning
16 /// [`configbuilder_pattern_loader::ConfigError`] directly for callers already
17 /// working in that error type (e.g. `configbuilder-svc-saf`'s
18 /// composition root). External consumers should prefer the [`Validator`] trait
19 /// impl below, which returns [`ValidatorError`].
20 pub fn validate_path(
21 &self,
22 target: &std::path::Path,
23 ) -> Result<(), configbuilder_pattern_loader::ConfigError> {
24 self.ops
25 .check_path(target)
26 .map_err(configbuilder_pattern_loader::ConfigError::from)
27 }
28}
29
30impl Validator for DefaultValidator {
31 fn validate_path(&self, target: &std::path::Path) -> Result<(), ValidatorError> {
32 self.ops.check_path(target)
33 }
34}