Expand description
Generic entity validation — composable field rules with typed errors.
Generated services get a type alias:
ⓘ
// Generated:
pub type StoredFileValidator = EntityValidator<StoredFile>;Custom decorators then add field rules without touching generated code:
ⓘ
// Custom:
impl StoredFileValidator {
pub fn with_business_rules() -> Self {
EntityValidator::new()
.rule(RequiredString::new("name", |e: &StoredFile| &e.name))
.rule(MaxLength::new("name", |e: &StoredFile| &e.name, 255))
.rule(NonNegative::new("size_bytes", |e: &StoredFile| e.size_bytes))
}
}Structs§
- Entity
Validator - Composable validator for any entity type
E. - MaxLength
- Fails if a string field exceeds
max_lenUnicode scalar values. - NonNegative
- Fails if a numeric field is negative.
- Optional
NotBlank - Fails if an
Option<String>field isSome("")orSome(" "). - Regex
- Fails if a string field doesn’t match the given regex pattern.
- Required
String - Fails if a string field is empty or whitespace-only.
- Required
Uuid - Fails if a UUID string field is empty or not a valid v4 UUID.
- Validation
Error - A single field-level validation failure.
- Validation
Errors - All validation errors collected from a single
validate()call.
Traits§
- Field
Rule - A single validation rule applied to an entity.