icydb_model/validate.rs
1//! Module: validate
2//!
3//! Responsibility: top-level validation entrypoint over visitable trees.
4//! Does not own: visitor diagnostics or per-type validation implementations.
5//! Boundary: convenient crate-level validation surface that delegates to visitor traversal.
6
7use crate::visitor::{
8 PathSegment, Visitable, VisitorAdapter, VisitorError, perform_visit, validate::ValidateVisitor,
9};
10
11///
12/// validate
13///
14/// Validate a visitable tree, collecting issues by path.
15///
16/// Validation is non-failing at the traversal level. All validation
17/// issues are collected and returned to the caller, which may choose
18/// how to interpret them.
19///
20/// # Errors
21///
22/// Returns `VisitorError` when one or more validators report an issue.
23///
24pub fn validate(node: &dyn Visitable) -> Result<(), VisitorError> {
25 let visitor = ValidateVisitor::new();
26 let mut adapter = VisitorAdapter::new(visitor);
27
28 perform_visit(&mut adapter, node, PathSegment::Empty);
29
30 adapter.result().map_err(VisitorError::from)
31}