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 @lengthon aBytesfield (cratestack#572).Bytesgenerates asVec<u8>, which has no character encoding to count against, so “length” here is unambiguously the byte count – unlikevalidate_length, which countschars (Unicode scalar values, not UTF-8 code units) becauseStringgenuinely has more than one plausible notion of “length”. AVec<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
@rangeenforcement. 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 likeamount 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