### Install Validator Crate Source: https://docs.rs/validator Add the validator dependency to your Cargo.toml file with the derive feature enabled. ```toml [dependencies] validator = { version = "0.16", features = ["derive"] } ``` -------------------------------- ### Validator Usage Example Source: https://docs.rs/validator/0.20.0/validator/index.html Demonstrates how to use the Validate derive macro to define validation rules on a struct and perform validation. ```APIDOC ## Rust Struct Validation ### Description Use the `#[derive(Validate)]` macro to define validation rules on struct fields. The `validate()` method is then used to check if the data conforms to these rules. ### Request Example ```rust #[derive(Debug, Validate, Deserialize)] struct SignupData { #[validate(email)] mail: String, #[validate(url)] site: String, #[validate(length(min = 1), custom(function = "validate_unique_username"))] first_name: String, #[validate(range(min = 18, max = 20))] age: u32, } ``` ### Response #### Success Response - **Result** (Ok) - Validation passed. #### Error Response - **Result** (Err) - Returns `ValidationErrors` containing details about failed validations. ``` -------------------------------- ### Struct Validation Example Source: https://docs.rs/validator/0.20.0/validator/index.html Demonstrates how to use the `Validate` derive macro for struct validation, including custom validation functions and various built-in validators like email, URL, length, and range. Ensure the `serde` crate is also included if using `Deserialize`. ```rust use serde::Deserialize; // A trait that the Validate derive will impl use validator::{Validate, ValidationError}; #[derive(Debug, Validate, Deserialize)] struct SignupData { #[validate(email)] mail: String, #[validate(url)] site: String, #[validate(length(min = 1), custom(function = "validate_unique_username"))] #[serde(rename = "firstName")] first_name: String, #[validate(range(min = 18, max = 20))] age: u32, } fn validate_unique_username(username: &str) -> Result<(), ValidationError> { if username == "xXxShad0wxXx" { // the value of the username will automatically be added later return Err(ValidationError::new("terrible_username")); } Ok(()) } match signup_data.validate() { Ok(_) => (), Err(e) => return e; }; ``` -------------------------------- ### Validator Crate Installation Source: https://docs.rs/validator/0.20.0/validator/index.html Add the validator crate to your project's `Cargo.toml` file. The `derive` feature is required for using the `#[derive(Validate)]` macro. ```toml [dependencies] validator = { version = "0.16", features = ["derive"] } ``` -------------------------------- ### ValidationError::description (Deprecated) Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Deprecated method for getting an error description. Use the Display impl or to_string() instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### Consume and Get Errors Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html The `into_errors` method consumes the `ValidationErrors` struct and returns the underlying HashMap of validation errors. ```rust pub fn into_errors(self) -> HashMap, ValidationErrorsKind> ``` -------------------------------- ### ValidationError::cause (Deprecated) Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Deprecated method for getting the underlying cause of an error. Replaced by Error::source. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### Get Field-Level Errors Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html The `field_errors` method returns a HashMap containing only the field-level validation errors for the validated struct. ```rust pub fn field_errors(&self) -> HashMap, &Vec> ``` -------------------------------- ### ValidateLength Trait Definition Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Defines the ValidateLength trait with methods for getting and validating length. The `validate_length` method prioritizes the `equal` parameter if provided. ```rust pub trait ValidateLength where T: PartialEq + PartialOrd, { // Required method fn length(&self) -> Option; // Provided method fn validate_length( &self, min: Option, max: Option, equal: Option, ) -> bool { ... } } ``` -------------------------------- ### Implement CloneToUninit for T (Nightly) Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Nightly-only experimental API for performing copy-assignment to uninitialized memory. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Implement Any for T Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Provides runtime type information for any type T. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### as_regex Method Implementation for &Arc>> Source: https://docs.rs/validator/0.20.0/validator/trait.AsRegex.html Implementation of the as_regex method for a reference to an Arc>>. ```rust fn as_regex(&self) -> Cow<'_, Regex> ``` -------------------------------- ### Type Conversion Utilities Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Details on generic type conversion traits, including TryFrom and TryInto. ```APIDOC ## Type Conversion Traits ### `TryFrom` for `T` #### Description This trait allows attempting a conversion from type `U` to type `T`. It returns a `Result` indicating success or failure. #### Method - `fn try_from(value: U) -> Result>::Error>`: Performs the conversion from `U` to `T`. ### `TryInto` for `T` #### Description This trait provides a convenient way to attempt a conversion from type `T` to type `U`, provided that `U` implements `TryFrom`. #### Method - `fn try_into(self) -> Result>::Error>`: Performs the conversion from `T` to `U`. #### Associated Type - `type Error = >::Error`: The type returned in the event of a conversion error. ``` -------------------------------- ### General Object Traits Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html Documentation for general traits like `Any`, `Borrow`, `BorrowMut`, and `UnwindSafe`. ```APIDOC ## General Object Traits ### Description This section details common traits applicable to various types, including trait object capabilities and borrowing. ### Traits #### `Any` - **`fn type_id(&self) -> TypeId`**: Gets the `TypeId` of `self`. #### `Borrow` - **`fn borrow(&self) -> &T`**: Immutably borrows from an owned value. #### `BorrowMut` - **`fn borrow_mut(&mut self) -> &mut T`**: Mutably borrows from an owned value. #### `UnwindSafe` - Blanket implementation for `ValidationErrors`. #### `DeserializeOwned` - Blanket implementation for types that implement `Deserialize`. #### `ErasedDestructor` - Blanket implementation for types that are `'static`. ### Usage Example (Borrow) ```rust let s = String::from("hello"); let borrowed_str: &str = s.borrow(); println!("{}", borrowed_str); ``` ``` -------------------------------- ### Define and Execute Validation Source: https://docs.rs/validator Demonstrates how to use the Validate derive macro on a struct and implement a custom validation function. ```rust use serde::Deserialize; // A trait that the Validate derive will impl use validator::{Validate, ValidationError}; #[derive(Debug, Validate, Deserialize)] struct SignupData { #[validate(email)] mail: String, #[validate(url)] site: String, #[validate(length(min = 1), custom(function = "validate_unique_username"))] #[serde(rename = "firstName")] first_name: String, #[validate(range(min = 18, max = 20))] age: u32, } fn validate_unique_username(username: &str) -> Result<(), ValidationError> { if username == "xXxShad0wxXx" { // the value of the username will automatically be added later return Err(ValidationError::new("terrible_username")); } Ok(()) } match signup_data.validate() { Ok(_) => (), Err(e) => return e; }; ``` -------------------------------- ### Type Conversion and Ownership Traits Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html Details common Rust traits for type conversion, borrowing, and ownership management. ```APIDOC ## Common Type Traits ### Description This section covers several standard Rust traits related to type conversions, borrowing, and ownership. ### Traits #### `CloneToUninit` - **`unsafe fn clone_to_uninit(&self, dest: *mut u8)`**: Performs copy-assignment from `self` to `dest`. (Nightly-only experimental API) #### `From` - **`fn from(t: T) -> T`**: Returns the argument unchanged. #### `Into` - **`fn into(self) -> U`**: Calls `U::from(self)`. The conversion behavior is determined by the `From for U` implementation. #### `ToOwned` - **`type Owned = T`**: The resulting type after obtaining ownership. - **`fn to_owned(&self) -> T`**: Creates owned data from borrowed data, usually by cloning. - **`fn clone_into(&self, target: &mut T)`**: Uses borrowed data to replace owned data, usually by cloning. #### `ToString` - **`fn to_string(&self) -> String`**: Converts the given value to a `String`. #### `TryFrom` - **`type Error = Infallible`**: The type returned in the event of a conversion error. - **`fn try_from(value: U) -> Result>::Error>`**: Performs the conversion. #### `TryInto` - **`type Error = >::Error`**: The type returned in the event of a conversion error. - **`fn try_into(self) -> Result>::Error>`**: Performs the conversion. ### Usage Example (TryInto) ```rust let value: i32 = 10; match value.try_into() { Ok(num) => println!("Converted successfully: {}", num), Err(e) => println!("Conversion failed: {:?}", e), } ``` ``` -------------------------------- ### Available Validations Source: https://docs.rs/validator/0.20.0/validator/index.html List of built-in validation rules provided by the crate. ```APIDOC ## Available Validation Rules - **email**: Validates email format based on HTML5 spec. - **url**: Validates string as a URL. - **length**: Validates length constraints (min/max/equal). - **range**: Validates numeric range (min/max/exclusive). - **must_match**: Validates that two fields match. - **contains / does_not_contain**: Checks for substring presence. - **custom**: Allows custom validation functions. - **regex**: Validates against a regular expression. - **credit_card**: Validates credit card format (requires `card` feature). - **non_control_character**: Validates against control characters (requires `unic` feature). - **required**: Validates that an Option is Some. ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional signed 64-bit integer values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: i64) -> Option Source #### fn less_than(&self, min: i64) -> Option ``` -------------------------------- ### as_url_string Method Signature Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateUrl.html The `as_url_string` method is required by the ValidateUrl trait. It returns an Option containing a string slice if the URL can be represented as a string, otherwise None. ```rust fn as_url_string(&self) -> Option>; ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional signed 64-bit integer values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: i64) -> Option Source #### fn less_than(&self, min: i64) -> Option ``` -------------------------------- ### ValidateRange Implementation for i64 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `i64` values. These methods are used to check if a signed 64-bit integer is outside a given range. ```rust impl ValidateRange for i64 Source #### fn greater_than(&self, max: i64) -> Option Source #### fn less_than(&self, min: i64) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional signed 8-bit integer values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: i8) -> Option Source #### fn less_than(&self, min: i8) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional signed 32-bit integer values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: i32) -> Option Source #### fn less_than(&self, min: i32) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional signed 32-bit integer values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: i32) -> Option Source #### fn less_than(&self, min: i32) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional signed 16-bit integer values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: i16) -> Option Source #### fn less_than(&self, min: i16) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional double-precision float values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: f64) -> Option Source #### fn less_than(&self, min: f64) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional signed 8-bit integer values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: i8) -> Option Source #### fn less_than(&self, min: i8) -> Option ``` -------------------------------- ### ValidateRange Implementation for f64 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `f64` values. These methods are used to check if a double-precision float is outside a given range. ```rust impl ValidateRange for f64 Source #### fn greater_than(&self, max: f64) -> Option Source #### fn less_than(&self, min: f64) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional double-precision float values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: f64) -> Option Source #### fn less_than(&self, min: f64) -> Option ``` -------------------------------- ### Implement From for T Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Provides a way to create a value of type T from another value of the same type. ```rust fn from(t: T) -> T ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional signed 16-bit integer values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: i16) -> Option Source #### fn less_than(&self, min: i16) -> Option ``` -------------------------------- ### ValidateIp Trait Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateIp.html Documentation for the ValidateIp trait, which provides methods to validate IPv4, IPv6, and general IP addresses. ```APIDOC ## Trait ValidateIp ### Summary This trait provides methods for validating IP addresses. ### Required Methods #### fn validate_ipv4(&self) -> bool Validates whether the given string is an IP V4 address. #### fn validate_ipv6(&self) -> bool Validates whether the given string is an IP V6 address. #### fn validate_ip(&self) -> bool Validates whether the given string is an IP address (either V4 or V6). ### Implementors #### impl ValidateIp for T This implementation allows any type that implements `ToString` to use the `ValidateIp` trait methods. ``` -------------------------------- ### ValidateRange Implementation for i32 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `i32` values. These methods are used to check if a signed 32-bit integer is outside a given range. ```rust impl ValidateRange for i32 Source #### fn greater_than(&self, max: i32) -> Option Source #### fn less_than(&self, min: i32) -> Option ``` -------------------------------- ### Implementations of ValidateRange Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Demonstrates implementations of the ValidateRange trait for various numeric types and their optional variants. ```APIDOC ## Implementations of ValidateRange ### `impl ValidateRange for f32` - `fn greater_than(&self, max: f32) -> Option` - `fn less_than(&self, min: f32) -> Option` ### `impl ValidateRange for f64` - `fn greater_than(&self, max: f64) -> Option` - `fn less_than(&self, min: f64) -> Option` ### `impl ValidateRange for i8` - `fn greater_than(&self, max: i8) -> Option` - `fn less_than(&self, min: i8) -> Option` ### `impl ValidateRange for i16` - `fn greater_than(&self, max: i16) -> Option` - `fn less_than(&self, min: i16) -> Option` ### `impl ValidateRange for i32` - `fn greater_than(&self, max: i32) -> Option` - `fn less_than(&self, min: i32) -> Option` ### `impl ValidateRange for i64` - `fn greater_than(&self, max: i64) -> Option` - `fn less_than(&self, min: i64) -> Option` ### `impl ValidateRange for i128` - `fn greater_than(&self, max: i128) -> Option` - `fn less_than(&self, min: i128) -> Option` ### `impl ValidateRange for isize` - `fn greater_than(&self, max: isize) -> Option` - `fn less_than(&self, min: isize) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: f32) -> Option` - `fn less_than(&self, min: f32) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: f64) -> Option` - `fn less_than(&self, min: f64) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: i8) -> Option` - `fn less_than(&self, min: i8) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: i16) -> Option` - `fn less_than(&self, min: i16) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: i32) -> Option` - `fn less_than(&self, min: i32) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: i64) -> Option` - `fn less_than(&self, min: i64) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: i128) -> Option` - `fn less_than(&self, min: i128) -> Option` ### `impl ValidateRange for Option` - `fn greater_than(&self, max: isize) -> Option` - `fn less_than(&self, min: isize) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: f32) -> Option` - `fn less_than(&self, min: f32) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: f64) -> Option` - `fn less_than(&self, min: f64) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: i8) -> Option` - `fn less_than(&self, min: i8) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: i16) -> Option` - `fn less_than(&self, min: i16) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: i32) -> Option` - `fn less_than(&self, min: i32) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: i64) -> Option` - `fn less_than(&self, min: i64) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: i128) -> Option` - `fn less_than(&self, min: i128) -> Option` ### `impl ValidateRange for Option>` - `fn greater_than(&self, max: isize) -> Option` - `fn less_than(&self, min: isize) -> Option` ``` -------------------------------- ### ValidateRange Implementation for i16 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `i16` values. These methods are used to check if a signed 16-bit integer is outside a given range. ```rust impl ValidateRange for i16 Source #### fn greater_than(&self, max: i16) -> Option Source #### fn less_than(&self, min: i16) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional float values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: f32) -> Option Source #### fn less_than(&self, min: f32) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional float values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: f32) -> Option Source #### fn less_than(&self, min: f32) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional signed pointer-sized integer values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: isize) -> Option Source #### fn less_than(&self, min: isize) -> Option ``` -------------------------------- ### Create New ValidationErrors Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html The `new` function is a constructor for creating an empty `ValidationErrors` instance. ```rust pub fn new() -> ValidationErrors ``` -------------------------------- ### ValidateRange Implementation for f32 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `f32` values. These methods are used to check if a float is outside a given range. ```rust impl ValidateRange for f32 Source #### fn greater_than(&self, max: f32) -> Option Source #### fn less_than(&self, min: f32) -> Option ``` -------------------------------- ### ValidateRange Implementation for i8 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `i8` values. These methods are used to check if a signed 8-bit integer is outside a given range. ```rust impl ValidateRange for i8 Source #### fn greater_than(&self, max: i8) -> Option Source #### fn less_than(&self, min: i8) -> Option ``` -------------------------------- ### ValidationError::fmt (Display) Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Formats the ValidationError for display using the given formatter. ```rust fn fmt(&self, fmt: &mut Formatter<'_>) -> Result ``` -------------------------------- ### ValidationError::new Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Creates a new ValidationError with a required error code. Use this to initialize a validation error. ```rust pub fn new(code: &'static str) -> ValidationError ``` -------------------------------- ### ValidateRange Implementation for Option> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option>`. This enables range checks on nested optional signed 128-bit integer values. ```rust impl ValidateRange for Option> Source #### fn greater_than(&self, max: i128) -> Option Source #### fn less_than(&self, min: i128) -> Option ``` -------------------------------- ### ValidateRange Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `Option`. This allows range checks on optional signed 128-bit integer values. ```rust impl ValidateRange for Option Source #### fn greater_than(&self, max: i128) -> Option Source #### fn less_than(&self, min: i128) -> Option ``` -------------------------------- ### ValidationError::provide Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Provides type-based access to context for error reports. This is a nightly-only experimental API. ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) ``` -------------------------------- ### ValidateLength Implementation for VecDeque Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for VecDeque, returning the number of elements as u64. ```rust impl ValidateLength for VecDeque fn length(&self) -> Option ``` -------------------------------- ### Implement TryInto for T Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Enables fallible conversion of a value of type T into a value of type U. ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Implement Serialize for ValidationErrorsKind Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Allows serializing ValidationErrorsKind values into a Serde serializer. ```rust fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer, ``` -------------------------------- ### Implement Into for T Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Enables conversion of a value of type T into a value of type U, where U implements From. ```rust fn into(self) -> U ``` -------------------------------- ### Implement PartialEq for ValidationErrorsKind Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Enables equality comparison between ValidationErrorsKind values. ```rust fn eq(&self, other: &ValidationErrorsKind) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### less_than Method Signature Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html The `less_than` method checks if the value is strictly less than the provided minimum. It returns an Option which might be None if the comparison cannot be performed. ```rust fn less_than(&self, min: T) -> Option ``` -------------------------------- ### Compare ValidationErrors for Equality Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html The `eq` method tests if two `ValidationErrors` instances are equal. ```rust fn eq(&self, other: &ValidationErrors) -> bool ``` -------------------------------- ### ValidateLength Implementation for &str Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for string slices, returning the length as u64. ```rust impl ValidateLength for &str fn length(&self) -> Option ``` -------------------------------- ### ValidateLength Implementation for String Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for String, returning the length as u64. ```rust impl ValidateLength for String fn length(&self) -> Option ``` -------------------------------- ### Implement TryFrom for T Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Enables fallible conversion from a value of type U into a value of type T. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### ValidationErrors Implementations Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html Utility methods for managing and querying validation errors. ```APIDOC ## impl ValidationErrors ### `pub fn new() -> ValidationErrors` Creates a new, empty `ValidationErrors` instance. ### `pub fn has_error( result: &Result<(), ValidationErrors>, field: &'static str, ) -> bool` Returns a boolean indicating whether a validation result includes validation errors for a given field. May be used as a condition for performing nested struct validations on a field in the absence of field-level validation errors. ### `pub fn merge_self( &mut self, field: &'static str, child: Result<(), ValidationErrors>, ) -> &mut ValidationErrors` Merges validation errors from a child result into the current `ValidationErrors` instance, associated with a specific field. ### `pub fn merge( parent: Result<(), ValidationErrors>, field: &'static str, child: Result<(), ValidationErrors>, ) -> Result<(), ValidationErrors>` Returns the combined outcome of a struct’s validation result along with the nested validation result for one of its fields. ### `pub fn merge_all( parent: Result<(), ValidationErrors>, field: &'static str, children: Vec>, ) -> Result<(), ValidationErrors>` Returns the combined outcome of a struct’s validation result along with the nested validation result for one of its fields where that field is a vector of validating structs. ### `pub fn errors(&self) -> &HashMap, ValidationErrorsKind>` Returns a map of field-level validation errors found for the struct that was validated and any of it’s nested structs that are tagged for validation. ### `pub fn errors_mut( &mut self, ) -> &mut HashMap, ValidationErrorsKind>` Returns a mutable map of field-level validation errors found for the struct that was validated and any of it’s nested structs that are tagged for validation. ### `pub fn into_errors(self) -> HashMap, ValidationErrorsKind>` Consumes the struct, returning the validation errors found. ### `pub fn field_errors(&self) -> HashMap, &Vec>` Returns a map of only field-level validation errors found for the struct that was validated. ### `pub fn add(&mut self, field: &'static str, error: ValidationError)` Adds a specific validation error to the given field. ### `pub fn is_empty(&self) -> bool` Checks if the `ValidationErrors` instance is empty (contains no errors). ``` -------------------------------- ### ValidateRange Implementation for isize Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `isize` values. These methods are used to check if a signed pointer-sized integer is outside a given range. ```rust impl ValidateRange for isize Source #### fn greater_than(&self, max: isize) -> Option Source #### fn less_than(&self, min: isize) -> Option ``` -------------------------------- ### ValidateLength Implementation for HashSet Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for HashSet, returning the number of elements as u64. ```rust impl ValidateLength for HashSet fn length(&self) -> Option ``` -------------------------------- ### validate_email Method Signature Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateEmail.html The provided `validate_email` method offers a default implementation for email validation. It leverages `as_email_string` to perform the validation based on the HTML5 specification. ```rust fn validate_email(&self) -> bool { ... } ``` -------------------------------- ### ValidateLength Implementation for HashMap Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for HashMap, returning the number of elements as u64. ```rust impl ValidateLength for HashMap fn length(&self) -> Option ``` -------------------------------- ### ValidateLength Implementation for str Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for string slices, returning the length as u64. ```rust impl ValidateLength for str fn length(&self) -> Option ``` -------------------------------- ### ValidateLength Implementation for BTreeSet Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for BTreeSet, returning the number of elements as u64. ```rust impl ValidateLength for BTreeSet fn length(&self) -> Option ``` -------------------------------- ### as_email_string Method Signature Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateEmail.html The required `as_email_string` method must be implemented by types that want to conform to the ValidateEmail trait. It returns an optional string slice representing the email. ```rust fn as_email_string(&self) -> Option>; ``` -------------------------------- ### ValidateLength Implementation for BTreeMap Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for BTreeMap, returning the number of elements as u64. ```rust impl ValidateLength for BTreeMap fn length(&self) -> Option ``` -------------------------------- ### Trait: AsRegex Source: https://docs.rs/validator/0.20.0/validator/trait.AsRegex.html Defines the interface for types that can be converted into a Regex. ```APIDOC ## Trait AsRegex ### Description A trait that provides a method to retrieve a regex instance, returning a Cow (Clone-on-write) reference to a Regex. ### Required Methods - **as_regex(&self) -> Cow<'_, Regex>** - Returns a reference or owned Regex instance. ### Implementors The trait is implemented for various types including: - Regex - LazyLock - &OnceLock - &Mutex> - &Mutex> - &Arc>> - &Arc>> - &T where T: AsRegex ``` -------------------------------- ### ValidateRange Implementation for i128 Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRange.html Provides implementations of `greater_than` and `less_than` for `i128` values. These methods are used to check if a signed 128-bit integer is outside a given range. ```rust impl ValidateRange for i128 Source #### fn greater_than(&self, max: i128) -> Option Source #### fn less_than(&self, min: i128) -> Option ``` -------------------------------- ### ValidateLength Implementation for Vec Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Vec, returning the number of elements as u64. ```rust impl ValidateLength for Vec fn length(&self) -> Option ``` -------------------------------- ### ValidateEmail Trait Methods Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateEmail.html Documentation for the methods provided by the ValidateEmail trait for email validation. ```APIDOC ## Trait: ValidateEmail ### Description Validates whether the given string is an email based on the HTML5 spec. RFC 5322 is not practical in most circumstances and allows email addresses that are unfamiliar to most users. ### Required Methods - **as_email_string(&self) -> Option>**: Returns the string representation of the email if valid. ### Provided Methods - **validate_email(&self) -> bool**: Returns true if the email is valid according to the HTML5 specification. ### Implementations - Cow<'_, str> - String - &'a str - Option where T: ValidateEmail - &T where T: ValidateEmail ``` -------------------------------- ### ValidateLength Implementation for [T] Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for slices, returning the number of elements as u64. ```rust impl ValidateLength for [T] fn length(&self) -> Option ``` -------------------------------- ### length Method Signature Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html The required `length` method signature within the ValidateLength trait. ```rust fn length(&self) -> Option; ``` -------------------------------- ### Function Signature for validate_must_match Source: https://docs.rs/validator/0.20.0/validator/fn.validate_must_match.html This is the function signature for `validate_must_match`. It validates that two given fields match. Both fields are optional. ```rust pub fn validate_must_match(a: T, b: T) -> bool ``` -------------------------------- ### Option Implementation Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateContains.html Implementation of ValidateContains for Option. ```APIDOC ## impl ValidateContains for Option ### Description Allows checking for substring containment within an `Option`. If the `Option` is `Some`, it delegates to the inner type's `validate_contains` method. If `None`, it returns `false`. ### Constraints - `T: ValidateContains` ### Method Signature ```rust fn validate_contains(&self, needle: &str) -> bool; ``` ``` -------------------------------- ### ValidateRegex for &str Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateRegex.html Implementation of ValidateRegex for string slices. Allows direct validation of string literals or slices against a regex. ```rust fn validate_regex(&self, regex: impl AsRegex) -> bool; ``` -------------------------------- ### Implement Debug for ValidationErrorsKind Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Enables the debugging representation of ValidationErrorsKind values. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### ValidateLength Implementation for Cow<'_, T> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Cow<'_, T>, delegating to the inner type's implementation. ```rust impl ValidateLength for Cow<'_, T> where T: ToOwned + ?Sized, for<'a> &'a T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### String Implementation Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateContains.html Implementation of ValidateContains for the String type. ```APIDOC ## impl ValidateContains for String ### Description Allows checking if a String contains a given substring. ### Method Signature ```rust fn validate_contains(&self, needle: &str) -> bool; ``` ``` -------------------------------- ### ValidateLength Implementation for Ref<'_, T> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Ref<'_, T>, delegating to the inner type's implementation. ```rust impl ValidateLength for Ref<'_, T> where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### ValidationError::clone_from Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Performs copy-assignment from another ValidationError. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### HashMap Implementation Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateContains.html Implementation of ValidateContains for HashMap. ```APIDOC ## impl ValidateContains for HashMap ### Description Allows checking if any of the keys (which are Strings) in a HashMap contain the given substring. ### Method Signature ```rust fn validate_contains(&self, needle: &str) -> bool; ``` ``` -------------------------------- ### Into::into Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Converts a ValidationError into another type that can be created from it. ```rust fn into(self) -> U where U: From, ``` -------------------------------- ### String Slice Implementation Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateContains.html Implementation of ValidateContains for string slices (&str). ```APIDOC ## impl<'a> ValidateContains for &'a str ### Description Allows checking if a string slice contains a given substring. ### Method Signature ```rust fn validate_contains(&self, needle: &str) -> bool; ``` ``` -------------------------------- ### Reference Implementation Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateContains.html Implementation of ValidateContains for references (&T). ```APIDOC ## impl ValidateContains for &T ### Description Allows checking for substring containment through a reference to a type that implements `ValidateContains`. ### Constraints - `T: ValidateContains` ### Method Signature ```rust fn validate_contains(&self, needle: &str) -> bool; ``` ``` -------------------------------- ### Implement Clone for ValidationErrorsKind Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Provides functionality to create a duplicate of a ValidationErrorsKind value. ```rust fn clone(&self) -> ValidationErrorsKind ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### ValidationError Trait Implementations Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Details the various trait implementations for ValidationError, enabling functionalities like cloning, debugging, serialization, and error handling. ```APIDOC ### Trait Implementations for ValidationError - **Clone**: Allows creating copies of `ValidationError`. - **Debug**: Enables debugging output for `ValidationError`. - **Deserialize**: Allows deserializing `ValidationError` from various formats. - **Display**: Provides a user-friendly string representation of `ValidationError`. - **Error**: Implements the standard Rust `Error` trait, including deprecated `description` and `cause` methods, and the modern `source` method. Also includes experimental `provide` method. - **PartialEq**: Enables comparison of `ValidationError` instances for equality. - **Serialize**: Allows serializing `ValidationError` into various formats. - **StructuralPartialEq**: Enables structural comparison of `ValidationError` instances. ``` -------------------------------- ### ToOwned::clone_into Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Uses borrowed data to replace owned data, usually by cloning. ```rust fn clone_into(&self, target: &mut T) where T: Clone, ``` -------------------------------- ### ValidateLength Implementation for Option Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Option, delegating to the inner type's implementation if Some. ```rust impl ValidateLength for Option where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### Cow Implementation Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateContains.html Implementation of ValidateContains for the Cow<'a, T> type. ```APIDOC ## impl<'cow, T> ValidateContains for Cow<'cow, T> ### Description Allows checking for substring containment within a `Cow` (Clone-on-Write) string. ### Constraints - `T: ToOwned + ?Sized` - `&'a T: ValidateContains` for all `'a` ### Method Signature ```rust fn validate_contains(&self, needle: &str) -> bool; ``` ``` -------------------------------- ### ValidateLength Implementation for Box Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Box, delegating to the inner type's implementation. ```rust impl ValidateLength for Box where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### ValidateLength Implementation for [T; N] Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for arrays, returning the number of elements as u64. ```rust impl ValidateLength for [T; N] fn length(&self) -> Option ``` -------------------------------- ### ValidationError::source Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Returns the lower-level source of this error, if any. ```rust fn source(&self) -> Option<&(dyn Error + 'static)> ``` -------------------------------- ### Implement Deserialize for ValidationErrorsKind Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Allows deserializing ValidationErrorsKind values from a Serde deserializer. ```rust fn deserialize<__D>(__deserializer: __D) -> Result where __D: Deserializer<'de>, ``` -------------------------------- ### ValidateLength Implementation for RefMut<'_, T> Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for RefMut<'_, T>, delegating to the inner type's implementation. ```rust impl ValidateLength for RefMut<'_, T> where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### ValidateLength Implementation for &T Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for references, delegating to the inner type's implementation. ```rust impl ValidateLength for &T where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### Implement ToOwned for T Source: https://docs.rs/validator/0.20.0/validator/enum.ValidationErrorsKind.html Provides methods for creating owned data from borrowed data. ```rust type Owned = T ``` ```rust fn to_owned(&self) -> T ``` ```rust fn clone_into(&self, target: &mut T) ``` -------------------------------- ### ToString::to_string Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Converts the ValidationError into a String. ```rust fn to_string(&self) -> String where T: Display + ?Sized, ``` -------------------------------- ### ValidateLength Implementation for Arc Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Arc, delegating to the inner type's implementation. ```rust impl ValidateLength for Arc where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### Check if Empty Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationErrors.html The `is_empty` method returns a boolean indicating whether the `ValidationErrors` struct contains any errors. ```rust pub fn is_empty(&self) -> bool ``` -------------------------------- ### ValidateLength Implementation for Rc Source: https://docs.rs/validator/0.20.0/validator/trait.ValidateLength.html Implementation of ValidateLength for Rc, delegating to the inner type's implementation. ```rust impl ValidateLength for Rc where T: ValidateLength, fn length(&self) -> Option ``` -------------------------------- ### IP Validation API Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Provides methods to validate if a string represents an IPv4, IPv6, or a general IP address. ```APIDOC ## Validate IP Address ### Description Provides methods to validate IP address formats. ### Methods #### `validate_ipv4(&self) -> bool` Validates whether the given string is an IP V4 address. #### `validate_ipv6(&self) -> bool` Validates whether the given string is an IP V6 address. #### `validate_ip(&self) -> bool` Validates whether the given string is a general IP address (either IPv4 or IPv6). ### Usage These methods are typically used on types that implement the `ToString` trait, allowing them to be checked for IP address validity. ``` -------------------------------- ### ValidationError Methods Source: https://docs.rs/validator/0.20.0/validator/struct.ValidationError.html Provides methods for creating and modifying ValidationError instances. ```APIDOC ### impl ValidationError #### pub fn new(code: &'static str) -> ValidationError Creates a new `ValidationError` with the given error code. #### pub fn add_param(&mut self, name: Cow<'static, str>, val: &T) Adds a parameter to the `ValidationError`. #### pub fn with_message(self, message: Cow<'static, str>) -> ValidationError Adds a custom message to a `ValidationError`. ```