Expand description
Validation for structs and enums: write rules on their fields, and get every problem back at once.
Validate::validate checks a value. It returns Ok(()), or every Issue it found. Each issue is a
Problem and the Path where it was found. Validate::validate_fail_fast returns only the first issue,
which is the one validate would list first. Fields are reported under the names serde reads them by.
With the serde feature, on by default, #[derive(Deserialize)] checks a struct while it is deserialized:
from_deserializerreturns every missing field and broken rule together.- serde’s own
Deserializeworks too. For a struct that breaks its rules, it returns an error with every issue in its message.
The json feature adds json::from_str and json::from_slice, which read JSON this way.
The json-schema feature adds json_schema::write_rules, which writes a struct’s rules into the JSON Schema
that a schema library generated for it, so an API’s document says what the rules require.
Modules§
- json
json - Reading JSON with collecting deserialization: every missing field and broken rule in one error.
- json_
schema json-schema - Writing a type’s rules into its JSON Schema, so that an API’s document says what its rules require.
- rules
- The built-in rules.
Structs§
- Field
Rules json-schema - The rules of one field: its name, and what they require of its value.
- Issue
- One thing wrong with a value, and the path where it was found: a broken rule, a missing field or a value of the wrong type.
- Issues
- Every issue found in one validation. This is the error type, and it is never empty.
- Location
- The place in a value that validation has reached. It is kept on the stack while validation descends into the value.
- Path
- Where in a value an issue was found: the segments that lead from the validated value down to it.
- Report
- The issues found so far in one validation. Validation adds to it as it goes through a value.
- Rules
json-schema - A type’s rules, as data: what
#[validate(...)]requires of each of its fields. - Value
Rules json-schema - What rules require of one value: a field’s, or an element’s.
Enums§
- Bounds
- The values a rule accepts. Both ends are included.
- Deserialize
Error serde - Why a value couldn’t be deserialized: the format’s own error, or the issues found in it.
- Length
Unit - What a length is counted in.
- Param
Value - The value of one of a
Problem’s named parameters: a number or text. - Path
Segment - One step of a
Path. - Problem
- The kind of issue: a stable code, its named parameters and an English message.
Traits§
- Deserialize
serde - A value that can be deserialized while collecting the issues in it: missing fields and broken rules together, instead of stopping at the first.
- Rule
- A check that a value of type
Tmust pass, written in#[validate(...)]. - Validate
- A value that can be checked against its rules.
Functions§
- from_
deserializer serde - Reads a
Tfromdeserializer, collecting every issue in it. - from_
deserializer_ fail_ fast serde - Reads a
Tfromdeserializer, and returns only its first issue.
Derive Macros§
- Deserialize
serde - Implements
Deserialize, and serde’s ownDeserializethrough it, for a struct with named fields or an enum. Deserializing it reports every missing field and broken rule together. - Validate
- Implements
Validatefrom the#[validate(...)]rules on the fields of a struct, or of an enum’s variants.