Skip to main content

Module validators

Module validators 

Expand description

Field-level validators.

Standalone helpers invoked from generated validate methods on Create / Update input structs. Each returns Ok(()) on success or a redacted CratestackError::Validation whose public message names the field but never echoes the rejected value (so PII does not leak via 422 bodies).

Functions§

validate_email
Pragmatic email check: requires exactly one @, non-empty local and domain parts, at least one . in the domain, and no whitespace. Not a full RFC 5322 grammar — that grammar admits forms (quoted local parts, IP literals) banks rarely accept anyway. Reject early; let real KYC flows do deeper validation.
validate_iso4217
ISO 4217 currency codes are 3 ASCII uppercase letters. We do not enforce the registered set here — that table churns and is downstream policy. Banks typically pin allowed currencies via a separate allow-list anyway.
validate_length
validate_length_bytes
@length on a Bytes field (cratestack#572). Bytes generates as Vec<u8>, which has no character encoding to count against, so “length” here is unambiguously the byte count – unlike validate_length, which counts chars (Unicode scalar values, not UTF-8 code units) because String genuinely has more than one plausible notion of “length”. A Vec<u8> doesn’t have that ambiguity, which is why this is a separate function dispatched by scalar type (cratestack-macros/src/validators/emit.rs::emit_length) rather than a shared generic: fixed-width digest/hash columns are the motivating use case (digest Bytes @length(min: 32, max: 32)).
validate_range_decimal
Decimal-typed @range enforcement. The parser accepts integer bounds (@range(min: 0, max: 100)) on both Int and Decimal fields; the i64 bounds are promoted to Decimal here so monetary fields can declare the same shape as integer counters. Banks routinely write things like amount Decimal @range(min: 0) to forbid negative amounts at the framework layer — without this, the validator silently no-ops and out-of-range values reach the database.
validate_range_i64
validate_uri