Skip to main content

pactum_annotations/
lib.rs

1//! Declarative field normalization and validation for pactum contracts.
2//!
3//! This crate is IO-free. Hosts and codecs call `Normalize` and `Validate` around
4//! serialization; they do not live here.
5
6mod checks;
7mod civil_date;
8mod context;
9mod email;
10mod error;
11mod formats;
12mod norms;
13mod phone;
14mod schema;
15mod traits;
16
17pub use checks::{
18    alphanumeric, ascii, bool_is_true, digits, ends_with, finite_f64, list_len, list_unique,
19    list_unique_strings, non_empty, non_negative_i64, number_f64, number_i64, one_of, positive_i64,
20    prefix_nested, starts_with, string_len, timestamp_ms, LengthUnit, NumericValue,
21};
22pub use civil_date::{check_rfc3339, check_ymd, CivilDate};
23pub use context::ValidationContext;
24pub use email::check_email;
25pub use error::FieldIssue;
26pub use formats::{check_charset, check_slug, check_url, check_uuid};
27pub use norms::{clamp_f64, clamp_i64, lowercase, strip_whitespace, trim, uppercase, ClampNum};
28pub use phone::{check_phone_e164, check_phone_locale, dial_plan, DialPlan, DIAL_PLANS};
29pub use schema::{CommandSpec, FieldSchema, InvariantSpec, ModelKind, ModelSchema, VariantSchema};
30pub use traits::{CheckOutcome, DescribeModel, Normalize, Validate};
31
32/// Derive `Normalize`, `Validate`, and `DescribeModel` from `#[norm]` / `#[check]` / `#[constraint]`.
33pub use pactum_annotations_macros::Model;
34
35/// Alias for [`Model`] when disambiguation is preferred.
36pub use pactum_annotations_macros::PactumModel;
37
38/// Mark a pure function as a reusable field rule (`#[check(rule = …)]`).
39pub use pactum_annotations_macros::pactum_rule;
40
41/// Define composable, schema-aware normalizer + check pipelines.
42pub use pactum_annotations_macros::define_rule;
43
44/// Helper used by generated constraint code.
45pub fn constraint_issue(field: &str, code: &str, reason: &str) -> FieldIssue {
46    FieldIssue::new(field, code, reason)
47}