Skip to main content

validate_length_bytes

Function validate_length_bytes 

pub fn validate_length_bytes(
    field: &'static str,
    value: &[u8],
    min: Option<usize>,
    max: Option<usize>,
) -> Result<(), CratestackError>
Expand description

@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)).