reliakit-validate
Composable validation traits and error types for Rust structs and values.
reliakit-validate provides a small set of types for expressing validation rules as part of a type's contract, collecting multiple failures at once, and carrying proof of validation in the type system.
The crate has no dependencies and forbids unsafe code.
When To Use It
Use this crate when:
- a struct or value has validity rules that go beyond what a type alone can express,
- you want to collect all validation failures at once rather than short-circuiting on the first one,
- you want function signatures to carry proof that a value was validated (
Valid<T>), - you are building a form, API handler, config loader, or CLI where user-facing error messages should name the failing field.
When Not To Use It
This crate covers struct- and value-level validation rules. The following are out of scope:
- type-level constraints at construction time, which belong in
reliakit-primitives, - schema validation and deserialization, which belong in a dedicated parsing library,
- domain-specific business rules, which belong in your own code.
Installation
[]
= "0.3"
For no_std environments:
[]
= { = "0.3", = false, = ["alloc"] }
Examples
Single-field validation
use ;
;
let score = new.unwrap;
assert_eq!;
assert!;
Multi-field struct validation
use ;
let result = CreateUser .validate;
let err = result.unwrap_err;
assert_eq!;
Building errors with chaining
use ;
let error = empty
.with
.with;
assert_eq!;
println!; // "email: invalid format; password: too short"
API Overview
| Item | Description |
|---|---|
Validate |
Trait for types that can validate themselves |
Valid<T> |
Zero-cost wrapper carrying proof of successful validation |
ValidationError |
Error collecting one or more Violations |
Violation |
A single failed constraint with optional field name |
ValidateResult<T> |
Result<T, ValidationError> alias |
Feature Flags
| Flag | Default | Description |
|---|---|---|
std |
yes | Enables std::error::Error for ValidationError; implies alloc |
alloc |
no | Enables ValidationError and ValidateResult (backed by Vec) |
no_std
The crate supports no_std. The Validate trait, Valid<T>, and Violation
are available without alloc — implement Validate with your own error type in
allocation-free contexts. ValidationError and ValidateResult require the
alloc feature (enabled by default via std).
Safety
This crate is #![forbid(unsafe_code)].
Minimum Supported Rust Version
Rust 1.85 stable. No nightly features are used.
Status
Active. The 0.1.x API is considered stable.
Contributing
See CONTRIBUTING.md.
License
Licensed under the MIT License.