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
17#[doc(hidden)]
18pub use async_trait as __async_trait;
19
20pub use checks::{
21    alphanumeric, ascii, bool_is_true, digits, ends_with, finite_f64, list_len, list_unique,
22    list_unique_strings, non_empty, non_negative_i64, number_f64, number_i64, one_of, positive_i64,
23    prefix_nested, starts_with, string_len, timestamp_ms, LengthUnit, NumericValue,
24};
25pub use civil_date::{check_rfc3339, check_ymd, CivilDate};
26pub use context::ValidationContext;
27pub use email::check_email;
28pub use error::{AsyncValidationError, FieldIssue, HostError};
29pub use formats::{check_charset, check_slug, check_url, check_uuid};
30pub use norms::{clamp_f64, clamp_i64, lowercase, strip_whitespace, trim, uppercase, ClampNum};
31pub use phone::{check_phone_e164, check_phone_locale, dial_plan, DialPlan, DIAL_PLANS};
32pub use schema::{CommandSpec, FieldSchema, InvariantSpec, ModelKind, ModelSchema, VariantSchema};
33pub use traits::{
34    AsyncCheckOutcome, AsyncCheckResult, AsyncValidate, CheckOutcome, Client, DescribeModel,
35    IntoAsyncError, Normalize, ScopedValidate, Server, Validate,
36};
37
38/// Derive `Normalize`, `Validate`, and `DescribeModel` from `#[norm]` / `#[check]` / `#[constraint]`.
39pub use pactum_annotations_macros::Model;
40
41/// Alias for [`Model`] when disambiguation is preferred.
42pub use pactum_annotations_macros::PactumModel;
43
44/// Mark a pure function as a reusable field rule (`#[check(rule = …)]`).
45pub use pactum_annotations_macros::pactum_rule;
46
47/// Define composable, schema-aware normalizer + check pipelines.
48pub use pactum_annotations_macros::define_rule;
49
50/// Helper used by generated constraint code.
51pub fn constraint_issue(field: &str, code: &str, reason: &str) -> FieldIssue {
52    FieldIssue::new(field, code, reason)
53}