pactum-annotations 0.1.0

Declarative field normalization and validation for pactum contracts
Documentation
//! Declarative field normalization and validation for pactum contracts.
//!
//! This crate is IO-free. Hosts and codecs call `Normalize` and `Validate` around
//! serialization; they do not live here.

mod checks;
mod civil_date;
mod context;
mod email;
mod error;
mod formats;
mod norms;
mod phone;
mod schema;
mod traits;

pub use checks::{
    alphanumeric, ascii, bool_is_true, digits, ends_with, finite_f64, list_len, list_unique,
    list_unique_strings, non_empty, non_negative_i64, number_f64, number_i64, one_of, positive_i64,
    prefix_nested, starts_with, string_len, timestamp_ms, LengthUnit, NumericValue,
};
pub use civil_date::{check_rfc3339, check_ymd, CivilDate};
pub use context::ValidationContext;
pub use email::check_email;
pub use error::FieldIssue;
pub use formats::{check_charset, check_slug, check_url, check_uuid};
pub use norms::{clamp_f64, clamp_i64, lowercase, strip_whitespace, trim, uppercase, ClampNum};
pub use phone::{check_phone_e164, check_phone_locale, dial_plan, DialPlan, DIAL_PLANS};
pub use schema::{CommandSpec, FieldSchema, InvariantSpec, ModelKind, ModelSchema, VariantSchema};
pub use traits::{CheckOutcome, DescribeModel, Normalize, Validate};

/// Derive `Normalize`, `Validate`, and `DescribeModel` from `#[norm]` / `#[check]` / `#[constraint]`.
pub use pactum_annotations_macros::Model;

/// Alias for [`Model`] when disambiguation is preferred.
pub use pactum_annotations_macros::PactumModel;

/// Mark a pure function as a reusable field rule (`#[check(rule = …)]`).
pub use pactum_annotations_macros::pactum_rule;

/// Define composable, schema-aware normalizer + check pipelines.
pub use pactum_annotations_macros::define_rule;

/// Helper used by generated constraint code.
pub fn constraint_issue(field: &str, code: &str, reason: &str) -> FieldIssue {
    FieldIssue::new(field, code, reason)
}