1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Type-safe validation traits and immutable validator registries.
//!
//! Use [`Validator`] for direct typed validation. Use a prepared adapter when
//! a domain rule must cross an erased input boundary. For configured execution,
//! declare [`ValidatorSignature`] values in a [`ValidatorDescriptor`], register
//! the descriptor, then bind it into a reusable [`BoundValidator`]. Aggregate
//! bound results explicitly with [`ValidationReport`] when a caller needs a
//! report; this crate does not schedule rules.
//!
//! A prepared validator is a lower-level entry point. Direct callers must
//! provide a context that satisfies its declared dependency contract; bound
//! execution performs the input and dependency checks before invoking it.
//!
//! # Direct typed validation
//!
//! ```
//! use std::fmt;
//!
//! use qubit_validator::Validator;
//!
//! struct Positive;
//! #[derive(Debug)]
//! struct NotPositive;
//!
//! impl fmt::Display for NotPositive {
//! fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
//! formatter.write_str("value must be positive")
//! }
//! }
//! impl std::error::Error for NotPositive {}
//!
//! impl Validator<i32> for Positive {
//! type Error = NotPositive;
//!
//! fn validate(&self, value: &i32, _: &()) -> Result<(), Self::Error> {
//! if *value > 0 { Ok(()) } else { Err(NotPositive) }
//! }
//! }
//!
//! Positive.validate(&7, &()).unwrap();
//! assert!(Positive.validate(&0, &()).is_err());
//! ```
//!
//! # Configured validation and reporting
//!
//! ```
//! use std::sync::Arc;
//!
//! use qubit_validator::{
//! ArgumentReader, BindError, BoundValidationContext, InputType,
//! PreparedValidator, RegistrationSource, ValidationOutcome, ValidationPath,
//! ValidationReport, ValidationValue, Validator, ValidatorDescriptor, ValidatorId,
//! ValidatorRegistration, ValidatorRegistry, ValidatorSignature, ViolationCode,
//! prepare_text_validator,
//! };
//!
//! struct NonBlank;
//! #[derive(Debug)]
//! struct Blank;
//! impl std::fmt::Display for Blank {
//! fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
//! formatter.write_str("blank name")
//! }
//! }
//! impl std::error::Error for Blank {}
//!
//! impl Validator<str> for NonBlank {
//! type Error = Blank;
//!
//! fn validate(&self, value: &str, _: &()) -> Result<(), Self::Error> {
//! if value.trim().is_empty() { Err(Blank) } else { Ok(()) }
//! }
//! }
//!
//! fn prepare(_reader: &mut ArgumentReader<'_>) -> Result<Arc<dyn PreparedValidator>, BindError> {
//! Ok(prepare_text_validator(NonBlank, |_| {
//! qubit_validator::ViolationDraft::new(qubit_validator::ViolationCode::new("text.blank"))
//! }))
//! }
//!
//! static SIGNATURES: &[ValidatorSignature] = &[ValidatorSignature::new(InputType::Text, &[], prepare)];
//! static DESCRIPTOR: ValidatorDescriptor = ValidatorDescriptor::new(SIGNATURES);
//! static REGISTRATION: ValidatorRegistration = ValidatorRegistration::new(
//! ValidatorId::new("profile.name.non_blank"),
//! &DESCRIPTOR,
//! RegistrationSource::new("profile-rules", "profile", "rules.rs", 1),
//! );
//!
//! let registry = ValidatorRegistry::from_registrations([®ISTRATION])?;
//! let rule = registry.bind("profile.name.non_blank", InputType::Text, &[])?;
//! let outcome = rule.validate(
//! ValidationValue::Text("Ada"),
//! &BoundValidationContext::new(&[]),
//! )?;
//! let mut report = ValidationReport::new();
//! report.record_outcome(0, ValidationPath::root().with_field("name"), outcome)?;
//! assert!(report.is_valid());
//!
//! let invalid = rule.validate(
//! ValidationValue::Text(" "),
//! &BoundValidationContext::new(&[]),
//! )?;
//! assert!(matches!(invalid, ValidationOutcome::Invalid(_)));
//! report.record_outcome(
//! 1,
//! ValidationPath::root().with_field("name"),
//! invalid,
//! )?;
//! assert!(!report.is_valid());
//! assert_eq!(report.violations()[0].code(), ViolationCode::new("text.blank"));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use NamedValidationArgument;
pub use ValidationArgument;
pub use ArgumentReader;
pub use BindError;
pub use BindErrorKind;
pub use BoundValidationContext;
pub use BoundValidator;
pub use DependencySpec;
pub use ExecutionError;
pub use ExecutionErrorKind;
pub use InputType;
pub use NamedValidationDependency;
pub use PrepareFn;
pub use PreparedOutcome;
pub use PreparedValidator;
pub use ValidationOutcome;
pub use ValidationValue;
pub use ViolationDraft;
pub use prepare_contextual_text_validator;
pub use prepare_contextual_typed_validator;
pub use prepare_text_domain_rule;
pub use prepare_text_validator;
pub use prepare_text_with_context;
pub use prepare_typed_domain_rule;
pub use prepare_typed_validator;
pub use prepare_typed_with_context;
pub use RegistrationSource;
pub use ValidatorDescriptor;
pub use ValidatorRegistration;
pub use ValidatorRegistrationFactory;
pub use ValidatorRegistry;
pub use ValidatorSignature;
pub use FailureId;
pub use PathSegment;
pub use RecordedOutcome;
pub use SkipReason;
pub use SkippedValidation;
pub use ValidationLimits;
pub use ValidationOutcomeError;
pub use ValidationPath;
pub use ValidationReport;
pub use Violation;
pub use ViolationCode;
pub use ViolationCodeError;
pub use ViolationParam;
pub use Validator;
pub use ValidatorId;
pub use ValidatorIdError;
pub use ValidatorRegistryError;