Expand description
Universal Data Validator
A comprehensive data validation library for Rust that works across API, database, and form contexts.
§Features
- Rich Validator Types: String, integer, float, bool, email, URL, UUID, date,
datetime, numeric, not-empty, enum, one-of, array (
Vec) and object (Map) - Schema-Based Validation: Define complex, nested data structures
- Custom Validators: Add your own validation logic
- Nullable & Optional: Fine-grained control over missing and
nullvalues - Strict Mode: Reject unknown fields
- Clear Error Messages: Detailed error reporting with full field paths
§Examples
use serde_json::json;
use universal_validator::{Schema, validators};
let schema = Schema::new()
.field("email", validators::email())
.field("age", validators::int().min(0).max(120))
.field("username", validators::string().min(3).max(20));
let data = json!({
"email": "user@example.com",
"age": 25,
"username": "john_doe"
});
let result = schema.validate(&data);
assert!(result.is_valid());Modules§
- codes
- Canonical error codes returned by validators.
- validators
- Factory functions for creating validators.
Structs§
- Bool
Validator - Validator for JSON booleans.
- Date
Validator - Validator for
YYYY-MM-DDdate strings. - Datetime
Validator - Validator for ISO-8601 style datetime strings.
- Email
Validator - Validator for email addresses.
- Enum
Validator - Validator that checks membership in a fixed set of JSON values (deep-equality semantics).
- Float
Validator - Validator for JSON numbers (integers and floats).
- IntValidator
- Validator for JSON integers.
- MapValidator
- Validator for JSON objects.
- NotEmpty
Validator - Validator that requires a non-empty string, array, or object.
- Numeric
Validator - Validator for strings that contain a valid JSON-style number.
- OneOf
Validator - Validator that accepts a value when at least one branch validator produces zero errors at the same field path.
- Schema
- A schema for validating top-level JSON objects.
- String
Validator - Validator for JSON strings.
- UrlValidator
- Validator for URLs.
- Uuid
Validator - Validator for UUID strings.
- Validation
Error - A single validation error.
- Validation
Errors - An aggregate of
ValidationErrors returned bySchema::try_validate. - Validation
Result - The result of validating a value or schema.
- VecValidator
- Validator for JSON arrays.
Constants§
- MAX_
PATTERN_ INPUT_ LENGTH - Maximum length (in Unicode scalar values) of a string that a
patterncheck will run against. Inputs longer than this skip the match and produce the normal pattern error.
Traits§
- Validator
- The trait implemented by all validators.