askr/validation/
mod.rs

1pub mod engine;
2pub mod priority;
3pub mod result;
4pub mod rules;
5
6pub use engine::ValidationEngine;
7pub use priority::Priority;
8pub use result::{PartialValidationResult, ValidationResult, ValidationSummary};
9
10/// Core trait for all validators
11pub trait Validator: Send + Sync {
12    /// Validate complete input
13    fn validate(&self, input: &str) -> ValidationResult;
14
15    /// Validate partial input during typing
16    fn partial_validate(&self, input: &str, cursor_pos: usize) -> PartialValidationResult;
17
18    /// Get the priority of this validator
19    fn priority(&self) -> Priority;
20
21    /// Get the name/identifier of this validator
22    fn name(&self) -> &str;
23
24    /// Get human-readable description of this validator
25    fn description(&self) -> &str {
26        self.name()
27    }
28}
29
30/// Configuration for a validation rule
31#[derive(Debug, Clone)]
32pub struct ValidationRuleConfig {
33    pub validator_type: ValidatorType,
34    pub priority: Option<Priority>,
35    pub custom_message: Option<String>,
36    pub parameters: std::collections::HashMap<String, String>,
37}
38
39#[derive(Debug, Clone)]
40pub enum ValidatorType {
41    Required,
42    MinLength(usize),
43    MaxLength(usize),
44    Pattern(String),
45    Email,
46    Hostname,
47    Url,
48    Ipv4,
49    Ipv6,
50    Integer,
51    Float,
52    Range(f64, f64),
53    Positive,
54    Negative,
55    Date(Option<String>),
56    Time(Option<String>),
57    DateTime(Option<String>),
58    Choices(Vec<String>),
59    FileExists,
60    DirExists,
61    PathExists,
62    Readable,
63    Writable,
64    Executable,
65}