icydb-core 0.70.0

IcyDB — A type-safe, embedded ORM and schema system for the Internet Computer
Documentation
//! Module: validate
//!
//! Responsibility: module-local ownership and contracts for validate.
//! Does not own: cross-module orchestration outside this module.
//! Boundary: exposes this module API while keeping implementation details internal.

use crate::{
    traits::Visitable,
    visitor::{
        PathSegment, VisitorAdapter, VisitorError, perform_visit, validate::ValidateVisitor,
    },
};

///
/// validate
/// Validate a visitable tree, collecting issues by path.
///
/// Validation is non-failing at the traversal level. All validation
/// issues are collected and returned to the caller, which may choose
/// how to interpret them.
///
pub fn validate(node: &dyn Visitable) -> Result<(), VisitorError> {
    let visitor = ValidateVisitor::new();
    let mut adapter = VisitorAdapter::new(visitor);

    perform_visit(&mut adapter, node, PathSegment::Empty);

    adapter.result().map_err(VisitorError::from)
}