facet-validate
facet-validate
Field validation during deserialization for the facet ecosystem.
Features
- Validation runs during deserialization, so errors include source spans (e.g., pointing to the exact JSON location)
- Custom validators with meaningful error messages via
Result<(), String> - Auto-deref:
fn(&str)validators work forStringfields
Usage
use Facet;
use facet_validate as validate;
Built-in Validators
| Validator | Syntax | Applies To |
|---|---|---|
min |
validate::min = 0 |
numbers |
max |
validate::max = 100 |
numbers |
min_length |
validate::min_length = 1 |
String, Vec, slices |
max_length |
validate::max_length = 100 |
String, Vec, slices |
email |
validate::email |
String |
url |
validate::url |
String |
regex |
validate::regex = r"..." |
String |
contains |
validate::contains = "foo" |
String |
custom |
validate::custom = fn_name |
any |
Integration
Enable the validate feature on facet-json (or other format crates):
[]
= { = "0.41", = ["validate"] }
= "0.41"
LLM contribution policy
Sponsors
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
Special thanks
The facet logo was drawn by Misiasart.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.