validator_async/lib.rs
1//! # Example:
2//!
3//! ```ignore, no_run
4//! use serde::Deserialize;
5//!
6//! // A trait that the Validate derive will impl
7//! use validator_async::{Validate, ValidationError};
8//!
9//! #[derive(Debug, Validate, Deserialize)]
10//! struct SignupData {
11//! #[validate(email)]
12//! mail: String,
13//! #[validate(url)]
14//! site: String,
15//! #[validate(length(min = 1), custom(function = "validate_unique_username"))]
16//! #[serde(rename = "firstName")]
17//! first_name: String,
18//! #[validate(range(min = 18, max = 20))]
19//! age: u32,
20//! }
21//!
22//! fn validate_unique_username(username: &str) -> Result<(), ValidationError> {
23//! if username == "xXxShad0wxXx" {
24//! // the value of the username will automatically be added later
25//! return Err(ValidationError::new("terrible_username"));
26//! }
27//!
28//! Ok(())
29//! }
30//!
31//! match signup_data.validate() {
32//! Ok(_) => (),
33//! Err(e) => return e;
34//! };
35//! ```
36//!
37//! # Available Validations:
38//! | Validation | Notes |
39//! | ----------------------- | ----------------------------------------------------- |
40//! | `email` | |
41//! | `url` | |
42//! | `length` | |
43//! | `range` | |
44//! | `must_match` | |
45//! | `contains` | |
46//! | `does_not_contain` | |
47//! | `custom` | |
48//! | `regex` | |
49//! | `credit_card` | (Requires the feature `card` to be enabled) |
50//! | `non_control_character` | |
51//! | `required` | |
52//!
53//! [Checkout the project README of an in-depth usage description with examples.](https://github.com/Keats/validator/blob/master/README.md)
54//!
55//! # Installation:
56//! Add the validator to the dependencies in the Cargo.toml file.
57//!
58//! ```toml
59//! [dependencies]
60//! validator = { version = "0.16", features = ["derive"] }
61//! ```
62
63mod display_impl;
64mod traits;
65mod types;
66mod validation;
67
68#[cfg(feature = "card")]
69pub use validation::cards::ValidateCreditCard;
70pub use validation::contains::ValidateContains;
71pub use validation::does_not_contain::ValidateDoesNotContain;
72pub use validation::email::ValidateEmail;
73pub use validation::ip::ValidateIp;
74pub use validation::length::ValidateLength;
75pub use validation::must_match::validate_must_match;
76pub use validation::non_control_character::ValidateNonControlCharacter;
77pub use validation::range::ValidateRange;
78pub use validation::regex::{AsRegex, ValidateRegex};
79pub use validation::required::ValidateRequired;
80pub use validation::urls::ValidateUrl;
81
82pub use traits::{Validate, ValidateArgs};
83pub use types::{ValidationError, ValidationErrors, ValidationErrorsKind};
84
85#[cfg(feature = "derive")]
86pub use validator_async_derive::Validate;