diff options
| author | Vincent Prouillet | 2017-01-16 20:56:05 +0900 | 
|---|---|---|
| committer | Vincent Prouillet | 2017-01-16 20:56:05 +0900 | 
| commit | ade9820f497d678296530bbf13bb4de46253d0fe (patch) | |
| tree | ab821e4d55e1fd2af4d0ef22e5c2336ba69343cf /README.md | |
| parent | 3302d261744c12001ec2cd980fffd32a829185aa (diff) | |
| download | validator-ade9820f497d678296530bbf13bb4de46253d0fe.tar.bz2 | |
Struct level validation
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 22 | 
1 files changed, 22 insertions, 0 deletions
| @@ -126,3 +126,25 @@ Examples:  ```  TODO: have it return a bool and pass a `code` to the `custom` validator instead? + +## Struct level validation +Often, some error validation can only be applied when looking at the full struct, here's how it works here: + + +```rust +#[derive(Debug, Validate, Deserialize)] +#[validate(schema(function = "validate_category", skip_on_field_errors = false)] +struct CategoryData { +    category: String, +    name: String, +} +``` + +The function mentioned should return a `Option<(String, String)>` where the tuple is (key error, error code) +and will be called after validation is done for all fields. +This means that the error can be reported on an existing field or on a new key. + +The `skip_on_field_errors` defaults to `true` if not present and will ensure that the function is not called +if an error happened while validating the struct fields. + + | 
