Skip to main content

Crate annotated

Crate annotated 

Source
Expand description

Validation for structs: 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_deserializer returns every missing field and broken rule together.
  • serde’s own Deserialize works 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.

Modules§

jsonjson
Reading JSON with collecting deserialization: every missing field and broken rule in one error.
rules
The built-in rules.

Structs§

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.

Enums§

Bounds
The values a rule accepts. Both ends are included.
DeserializeErrorserde
Why a value couldn’t be deserialized: the format’s own error, or the issues found in it.
LengthUnit
What a length is counted in.
ParamValue
The value of one of a Problem’s named parameters: a number or text.
PathSegment
One step of a Path.
Problem
The kind of issue: a stable code, its named parameters and an English message.

Traits§

Deserializeserde
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 T must pass, written in #[validate(...)].
Validate
A value that can be checked against its rules.

Functions§

from_deserializerserde
Reads a T from deserializer, collecting every issue in it.
from_deserializer_fail_fastserde
Reads a T from deserializer, and returns only its first issue.

Derive Macros§

Deserializeserde
Implements Deserialize, and serde’s own Deserialize through it, for a struct with named fields. Deserializing the struct reports every missing field and broken rule together.
Validate
Implements Validate from the #[validate(...)] rules on a struct’s fields.