-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
69 lines (66 loc) · 2.37 KB
/
lib.rs
File metadata and controls
69 lines (66 loc) · 2.37 KB
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
//! # walrs_validation
//!
//! Composable validation rules for input validation.
//!
//! This crate provides a serializable, composable validation rule system based on
//! the [`Rule`] enum, along with core validation traits.
//!
//! ## Validation Rules
//!
//! The [`Rule`] enum provides built-in validation for common constraints:
//! - `Rule::Required` - Value must not be empty
//! - `Rule::MinLength` / `Rule::MaxLength` - Length constraints
//! - `Rule::Min` / `Rule::Max` - Range constraints
//! - `Rule::Pattern` - Regex pattern matching
//! - `Rule::Email` - Email format validation
//! - `Rule::Url` - Configurable URL validation (scheme filtering)
//! - `Rule::Uri` - Configurable URI validation (scheme, relative/absolute)
//! - `Rule::Ip` - Configurable IP address validation (IPv4/IPv6/IPvFuture)
//! - `Rule::Hostname` - Configurable hostname validation (DNS/IP/local/public IPv4)
//! - `Rule::Date` - Configurable date format validation (ISO 8601, US, EU, custom)
//! - `Rule::DateRange` - Date range validation with min/max bounds
//! - `Rule::Step` - Step/multiple validation
//! - `Rule::Custom` - Custom closure-based validation
//!
//! ## Rule Composition
//!
//! Rules can be composed using methods on [`Rule`]:
//! - `.and()` - Both rules must pass (AND logic, produces `Rule::All`)
//! - `.or()` - At least one rule must pass (OR logic, produces `Rule::Any`)
//! - `.not()` - Negates a rule (produces `Rule::Not`)
//! - `.when()` / `.when_else()` - Conditional validation (produces `Rule::When`)
//!
//! ## Example
//!
//! ```rust
//! use walrs_validation::{Rule, Validate, ValidateRef};
//!
//! // Length validation using Rule
//! let length_rule = Rule::<String>::MinLength(3).and(Rule::MaxLength(20));
//!
//! assert!(length_rule.validate_ref("hello").is_ok());
//! assert!(length_rule.validate_ref("hi").is_err());
//!
//! // Range validation with combinators
//! let range_rule = Rule::<i32>::Min(0).and(Rule::Max(100));
//!
//! assert!(range_rule.validate(50).is_ok());
//! assert!(range_rule.validate(-1).is_err());
//! ```
#[cfg(feature = "indexmap")]
pub use indexmap;
pub mod attributes;
pub(crate) mod rule_impls;
pub mod message;
pub mod options;
pub mod rule;
pub mod traits;
pub mod value;
pub mod violation;
pub use attributes::*;
pub use message::*;
pub use options::*;
pub use rule::{CompiledRule, Condition, Rule, RuleResult};
pub use traits::*;
pub use value::*;
pub use violation::*;