Skip to content

Commit

Permalink
Update documentation for custom validations (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
divergentdave authored Mar 11, 2024
1 parent 53f22b8 commit 1dd03ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct SignupData {
mail: String,
#[validate(url)]
site: String,
#[validate(length(min = 1), custom = "validate_unique_username")]
#[validate(length(min = 1), custom(function = "validate_unique_username"))]
#[serde(rename = "firstName")]
first_name: String,
#[validate(range(min = 18, max = 20))]
Expand Down Expand Up @@ -281,9 +281,8 @@ which should return a `Result<(), ValidationError>`.
Examples:

```rust
#[validate(custom = "validate_something")]
#[validate(custom = "::utils::validate_something")]
#[validate(custom(function = "validate_something"))]
#[validate(custom(function = "::utils::validate_something"))]
```

You can also parse arguments from the validation function to your custom validation by setting the `arg` parameter. `arg` can only be set to one type but you can set it to a tuple to pass multiple types at once. Defining the `arg` parameter will implement the `ValidateArgs` trait with the corresponding function types like this:
Expand Down
2 changes: 1 addition & 1 deletion validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! mail: String,
//! #[validate(url)]
//! site: String,
//! #[validate(length(min = 1), custom = "validate_unique_username")]
//! #[validate(length(min = 1), custom(function = "validate_unique_username"))]
//! #[serde(rename = "firstName")]
//! first_name: String,
//! #[validate(range(min = 18, max = 20))]
Expand Down

0 comments on commit 1dd03ed

Please sign in to comment.