| Crates.io | facet-validate |
| lib.rs | facet-validate |
| version | 0.43.2 |
| created_at | 2026-01-06 13:16:13.942164+00 |
| updated_at | 2026-01-23 18:02:12.72157+00 |
| description | Validation attributes for facet - validate field values during deserialization |
| homepage | https://facet.rs |
| repository | https://github.com/facet-rs/facet |
| max_upload_size | |
| id | 2025849 |
| size | 28,655 |
Field validation during deserialization for the facet ecosystem.
Result<(), String>fn(&str) validators work for String fieldsuse facet::Facet;
use facet_validate as validate;
fn validate_positive(n: &i64) -> Result<(), String> {
if *n <= 0 {
Err(format!("must be positive, got {}", n))
} else {
Ok(())
}
}
#[derive(Facet)]
struct Product {
#[facet(validate::custom = validate_positive)]
price: i64,
}
| 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 |
Enable the validate feature on facet-json (or other format crates):
[dependencies]
facet-json = { version = "0.41", features = ["validate"] }
facet-validate = "0.41"
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
The facet logo was drawn by Misiasart.
Licensed under either of:
at your option.