Expand description
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.
use pactum_annotations::{trim, check_email};
let mut email = " User@Example.com ".to_string();
trim(&mut email);
assert_eq!(email, "User@Example.com");
assert!(check_email("email", &email).is_ok());Macros§
- define_
rule - Define composable, schema-aware normalizer + check pipelines. Define composable, schema-aware normalizer + validation pipelines.
Structs§
- Civil
Date - Calendar date without a time zone.
- Client
- Built-in scope marker for client-only validation checks.
- Command
Spec - Discoverable command: name, reply type, fields, and invariants.
- Dial
Plan - Dial-plan entry for a locale (ISO 3166-1 alpha-2).
- Field
Issue - One field (or whole-model) invariant that failed.
- Field
Schema - One field on a struct or enum variant.
- Host
Error - Infrastructure / host-resolver failure (distinct from domain
FieldIssuevalidation errors). - Invariant
Spec - One check or constraint the host may discover. Enforcement still runs in Rust.
- Model
Schema - Static description of a model for the contract catalog and IDL.
- Server
- Built-in scope marker for server-only validation checks.
- Validation
Context - Pure context passed into
validate_withso time-based checks stay deterministic. - Variant
Schema - One variant on a non-command enum (events, server frames, replies).
Enums§
- Async
Check Result - Outcome of an asynchronous check: either domain issues or a host/IO failure.
- Async
Validation Error - Failure returned by
crate::AsyncValidate: either domain field issues or a host/IO failure. - Length
Unit - Model
Kind
Constants§
Traits§
- Async
Check Outcome - Result types supported by
#[check(resolve(...))],#[check(async_with(...))], and async#[pactum_rule]. - Async
Validate - Run synchronous + asynchronous checks resolved via a host-implemented capability trait
R. - Check
Outcome - Result types supported by arbitrary
#[check(with = ...)]functions and closures. - Clamp
Num - Type-aware clamp supporting signed/unsigned integers and floats against
f64bounds without integer saturation, precision loss, orNaNcorruption. - Describe
Model - Emit static schema for the catalog and IDL.
- Into
Async Error - Error types convertible into
AsyncCheckResultinsideResult<(), E>andResult<bool, E>. - Into
Sync Error - Error types convertible into
FieldIssues inside synchronousResult<(), E>andResult<bool, E>checks. - Normalize
- Mutate a value into canonical form before checks.
- Numeric
Value - Type-aware numeric validation across integers and floating-point numbers.
- Scoped
Validate - Run shared +
Scope-specific synchronous field rules and cross-field constraints. - Validate
- Run field rules and cross-field constraints.
Functions§
- alphanumeric
- ascii
- bool_
is_ true - check_
charset - Validate every character against a compact character class spec such as
"a-z0-9_-". - check_
email - Structural email check: printable ASCII
local@domainwith a dotted domain and valid TLD. - check_
hex - Non-empty string of ASCII hexadecimal digits.
- check_
hostname - RFC 1123 ASCII hostname (labels of
[A-Za-z0-9-], max 63 bytes each, 253 total). - check_
ip - IPv4 or IPv6 address.
- check_
ipv4 - Strict dotted-quad IPv4 address.
- check_
ipv6 - IPv6 address (any textual form accepted by
core::net::Ipv6Addr). - check_
phone_ e164 - Strict ITU-T E.164: leading
+, non-zero country code digit, 7..=15 total digits. - check_
phone_ locale - Locale-aware phone: E.164 whose country code and national length match the dial plan.
- check_
rfc3339 - RFC 3339 timestamp:
YYYY-MM-DDTHH:MM:SS+ optional.frac+Zor±HH:MM. - check_
semver - Strict SemVer 2.0.0 (
MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]). - check_
slug - Lowercase ASCII slug:
[a-z0-9]segments joined by single-characters. - check_
url - Structural URL check (
http://orhttps://, valid host and optional port, no whitespace/control chars). - check_
uuid - Canonical lowercase/uppercase hyphenated UUID (
8-4-4-4-12hex digits). - check_
ymd - Parse
YYYY-MM-DD. - clamp_
f64 - clamp_
i64 - constraint_
issue - Helper used by generated constraint code.
- dial_
plan - digits
- ends_
with - finite_
f64 - list_
len - list_
unique - list_
unique_ strings - lowercase
- non_
empty - non_
negative_ i64 - number_
f64 - number_
i64 - one_of
- positive_
i64 - prefix_
nested - starts_
with - string_
len - strip_
whitespace - timestamp_
ms - trim
- uppercase
Attribute Macros§
- pactum_
rule - Mark a pure function as a reusable field rule (
#[check(rule = …)]). Mark a pure function as a reusable field rule (#[check(rule = name)]).
Derive Macros§
- Model
- Derive
Normalize,Validate, andDescribeModelfrom#[norm]/#[check]/#[constraint]. DeriveNormalize,Validate, andDescribeModelfrom#[norm]/#[check]/#[constraint]. - Pactum
Model - Alias for
Modelwhen disambiguation is preferred. Alias forModelwhen disambiguation is preferred.