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
//! # validkit
//!
//! Typed newtypes for validated domain primitives — replaces hand-rolled
//! `is_valid_*` checks with parse-once, use-everywhere strong types.
//!
//! | Type | Validation |
//! |------|------------|
//! | [`EmailAddr`] | RFC 5321 + IDNA, injection-safe |
//! | [`HttpsUrl`] | `https` only, no credentials, host required |
//! | [`PhoneE164`] | E.164 `^\+[1-9]\d{1,14}$` |
//! | [`CronExpr`] | 5-field cron (`*` or `[\d,/\-]+`) |
//! | [`TenantIdSlug`] | `3–63` chars, `[a-z0-9-]`, no `..`, no `.lock` |
//! | [`LocaleTag`] | BCP 47 `^[a-z]{2,3}(-[A-Za-z0-9]+)*$`, max 35 |
//! | [`FlagName`] | `^[a-z][a-z0-9_]*$` |
//! | [`BucketName`] | S3 bucket rules, not IP |
//! | [`ObjectKey`] | S3 object key, no `..` traversal, ≤1024, no leading `/` |
//!
//! ## Example
//!
//! ```rust
//! use validkit::{EmailAddr, HttpsUrl, TenantIdSlug};
//!
//! let email = EmailAddr::parse("alice@example.com").expect("valid");
//! assert_eq!(email.as_str(), "alice@example.com");
//!
//! let url = HttpsUrl::parse("https://example.com").expect("valid");
//! assert!(url.as_str().starts_with("https://"));
//!
//! let tenant = TenantIdSlug::parse("my-tenant").expect("valid");
//! assert_eq!(tenant.as_str(), "my-tenant");
//! ```
//!
//! All types implement `TryFrom<String>`, `FromStr`, `Display`, `Deref<Target=str>`,
//! and optional `serde` support (transparent serialization; deserialization
//! runs full validation, so invalid values cannot enter through JSON).
//!
//! # Derive macro
//!
//! Behind the optional, non-default `derive` feature, `#[derive(Validated)]`
//! generates a `validate(&self) -> Result<(), ValidError>` method that checks
//! fields annotated with `#[validate(...)]`:
//!
//! ```rust
//! #[cfg(feature = "derive")]
//! fn derive_example() {
//! use validkit::{Validated, Validate};
//!
//! #[derive(Validated)]
//! struct Contact {
//! #[validate(email)]
//! email: String,
//! #[validate(url)]
//! homepage: Option<String>,
//! #[validate(length(min = 1, max = 100))]
//! name: String,
//! #[validate(range(min = 0.0, max = 1.0))]
//! trust: f64,
//! #[validate(postcode_uk)]
//! postcode: String,
//! }
//!
//! let contact = Contact {
//! email: "alice@example.com".to_string(),
//! homepage: None,
//! name: "Alice".to_string(),
//! trust: 0.9,
//! postcode: "SW1A 1AA".to_string(),
//! };
//! assert!(contact.validate().is_ok());
//! }
//! # #[cfg(not(feature = "derive"))]
//! # fn main() {}
//! # #[cfg(feature = "derive")]
//! # fn main() { derive_example() }
//! ```
//!
//! Newtype-typed fields (`EmailAddr`, `HttpsUrl`) are supported as leaves —
//! the derive re-uses the newtype's validation rather than re-implementing
//! it.
//!
extern crate alloc;
// Re-exports
pub use is_valid_bucket_name;
pub use BucketName;
pub use is_valid_cron;
pub use CronExpr;
pub use check_postcode_uk;
pub use is_valid_email;
pub use EmailAddr;
pub use Validate;
pub use invalid_field;
pub use ValidError;
pub use is_valid_flag_name;
pub use FlagName;
pub use is_valid_locale;
pub use LocaleTag;
pub use is_valid_object_key;
pub use ObjectKey;
pub use PhoneE164;
pub use is_valid_tenant_id;
pub use TenantIdSlug;
pub use HttpsUrl;
// The `Validated` derive (behind the non-default `derive` feature).
pub use Validated;
// Tests exercise failure paths and invariants directly; unwrap/expect,
// slicing, and panicking asserts are acceptable here — violations
// surface as test failures, not production panics.