validator/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::{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 = "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` | (Required the feature `unic` to be enabled) |
51//! | `nested` | (Uses the validation of the field type it self) |
52//! | `required` | |
53//!
54//! [Checkout the project README of an in-depth usage description with examples.](https://github.com/Keats/validator/blob/master/README.md)
55//!
56//! # Installation:
57//! Add the validator to the dependencies in the Cargo.toml file.
58//!
59//! ```toml
60//! [dependencies]
61//! validator = { version = "0.16", features = ["derive"] }
62//! ```
63
64mod display_impl;
65mod traits;
66mod types;
67mod validation;
68
69#[cfg(feature = "card")]
70pub use validation::cards::ValidateCreditCard;
71pub use validation::contains::ValidateContains;
72pub use validation::does_not_contain::ValidateDoesNotContain;
73pub use validation::email::ValidateEmail;
74pub use validation::ip::ValidateIp;
75pub use validation::length::ValidateLength;
76pub use validation::must_match::validate_must_match;
77pub use validation::nested::ValidateNested;
78#[cfg(feature = "unic")]
79pub use validation::non_control_character::ValidateNonControlCharacter;
80pub use validation::range::ValidateRange;
81pub use validation::regex::ValidateRegex;
82pub use validation::required::ValidateRequired;
83pub use validation::urls::ValidateUrl;
84
85pub use traits::{Validate, ValidateArgs};
86pub use types::{ValidationError, ValidationErrors, ValidationErrorsKind};
87
88#[cfg(feature = "derive")]
89pub use validator_derive::Validate;