Skip to main content

icydb_model/
normalize.rs

1//! Module: normalize
2//!
3//! Responsibility: top-level normalize entrypoint over visitable trees.
4//! Does not own: visitor diagnostics or per-type normalize implementations.
5//! Boundary: convenient crate-level normalize surface that delegates to visitor traversal.
6
7use crate::visitor::{
8    ApplicationOperation, PathSegment, Visitable, VisitorError, VisitorMutAdapter,
9    normalize::NormalizeVisitor, perform_visit_mut,
10};
11
12///
13/// normalize
14///
15/// Run the normalizer visitor over a mutable visitable tree.
16///
17/// Traversal visits the complete value tree and aggregates any reported issues
18/// into the returned `VisitorError`.
19///
20/// # Errors
21///
22/// Returns `VisitorError` when one or more normalizers report an issue.
23///
24pub fn normalize(node: &mut dyn Visitable) -> Result<(), VisitorError> {
25    let visitor = NormalizeVisitor::new();
26    let mut adapter = VisitorMutAdapter::new(visitor);
27
28    perform_visit_mut(&mut adapter, node, PathSegment::Empty);
29
30    adapter
31        .result()
32        .map_err(|issues| VisitorError::new(ApplicationOperation::Normalize, issues))
33}