Skip to main content

Crate pactum_annotations

Crate pactum_annotations 

Source
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§

CivilDate
Calendar date without a time zone.
Client
Built-in scope marker for client-only validation checks.
CommandSpec
Discoverable command: name, reply type, fields, and invariants.
DialPlan
Dial-plan entry for a locale (ISO 3166-1 alpha-2).
FieldIssue
One field (or whole-model) invariant that failed.
FieldSchema
One field on a struct or enum variant.
HostError
Infrastructure / host-resolver failure (distinct from domain FieldIssue validation errors).
InvariantSpec
One check or constraint the host may discover. Enforcement still runs in Rust.
ModelSchema
Static description of a model for the contract catalog and IDL.
Server
Built-in scope marker for server-only validation checks.
ValidationContext
Pure context passed into validate_with so time-based checks stay deterministic.
VariantSchema
One variant on a non-command enum (events, server frames, replies).

Enums§

AsyncCheckResult
Outcome of an asynchronous check: either domain issues or a host/IO failure.
AsyncValidationError
Failure returned by crate::AsyncValidate: either domain field issues or a host/IO failure.
LengthUnit
ModelKind

Constants§

DIAL_PLANS

Traits§

AsyncCheckOutcome
Result types supported by #[check(resolve(...))], #[check(async_with(...))], and async #[pactum_rule].
AsyncValidate
Run synchronous + asynchronous checks resolved via a host-implemented capability trait R.
CheckOutcome
Result types supported by arbitrary #[check(with = ...)] functions and closures.
ClampNum
Type-aware clamp supporting signed/unsigned integers and floats against f64 bounds without integer saturation or NaN corruption.
DescribeModel
Emit static schema for the catalog and IDL.
IntoAsyncError
Error types convertible into AsyncCheckResult inside Result<(), E> and Result<bool, E>.
Normalize
Mutate a value into canonical form before checks.
NumericValue
Type-aware numeric validation across integers and floating-point numbers.
ScopedValidate
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 ASCII class spec such as "a-z0-9_-".
check_email
Structural email check: local@domain with a dotted domain and no control characters.
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 E.164: leading +, 7..=15 digits after the plus.
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 + Z or ±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:// or https://, non-empty host, no whitespace/control chars).
check_uuid
Canonical lowercase/uppercase hyphenated UUID (8-4-4-4-12 hex 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, and DescribeModel from #[norm] / #[check] / #[constraint]. Derive Normalize, Validate, and DescribeModel from #[norm] / #[check] / #[constraint].
PactumModel
Alias for Model when disambiguation is preferred. Alias for Model when disambiguation is preferred.