Expand description
Parametric type validators — Phase 4 partial drop.
The full Fase 3 plan calls for DataType::Varchar { max_len }
and DataType::Decimal { precision, scale } baked into the
DataType enum. That migration cascades into hundreds of
pattern-match sites and requires cargo verification to land
safely. Until that session runs, this module ships the
validators as standalone functions so the rest of the
codebase can use them today via coerce::coerce_via_catalog
without touching DataType.
Once the enum migration lands, these functions become the body of the cast-catalog entries for the parametric variants.
§Coverage
validate_varchar(s, max_len)— Postgres-strict (rejects strings longer thanmax_len). Configurable viaVarcharMode::Truncatefor SQL Server-style behavior.validate_decimal(value, precision, scale)— verifies the value fits inprecisiontotal digits withscaledigits after the decimal point.parse_varchar_modifier,parse_decimal_modifier— pull(n)/(p, s)out of the legacySqlTypeNamemodifiers so callers don’t reinvent the parsing.
Enums§
- Parametric
Error - Errors raised by the parametric validators.
- Varchar
Mode - VARCHAR length-check policy. Postgres rejects; SQL Server silently truncates. reddb defaults to Postgres-strict.
Functions§
- parse_
decimal_ modifier - Pull
(p, s)out ofDECIMAL(p, s)’s SqlTypeName modifiers. Returns(precision, scale)on success. - parse_
varchar_ modifier - Pull
(n)out ofVARCHAR(n)’s SqlTypeName modifiers. ReturnsErrif the modifier list is empty, has more than one element, or the single element isn’t aNumber. - validate_
decimal - Validate a
Value::Decimalagainst declared (precision, scale).precisionis the maximum total digit count (both sides of the decimal point);scaleis the maximum fractional digit count. - validate_
varchar - Validate a
Value::Textagainst a declared VARCHAR length limit. Returns the value unchanged on success, or a coerced truncated copy whenmode == Truncate.