Skip to main content

icydb_model/
application.rs

1//! Explicit application-owned normalization and validation composition.
2//!
3//! This module does not perform database admission, persistence, retries, or
4//! accepted-schema constraint evaluation.
5
6use crate::{normalize, validate, visitor::Visitable, visitor::VisitorError};
7
8/// Consuming normalize-then-validate convenience for application values.
9///
10/// The value is normalized first. Validation runs only if normalization
11/// succeeds, and the normalized value is returned only after both traversals
12/// succeed. The method consumes `self`, so it neither clones the value nor
13/// creates a second callback owner.
14pub trait NormalizeAndValidate: Visitable + Sized {
15    /// Normalize and then validate this application-owned value.
16    ///
17    /// # Errors
18    ///
19    /// Returns a typed [`VisitorError`] from the first failing stage. Use
20    /// [`VisitorError::operation`] to distinguish normalization from
21    /// validation without inspecting diagnostic prose.
22    fn normalize_and_validate(mut self) -> Result<Self, VisitorError> {
23        normalize(&mut self)?;
24        validate(&self)?;
25        Ok(self)
26    }
27}
28
29impl<T> NormalizeAndValidate for T where T: Visitable {}
30
31#[cfg(test)]
32mod tests;