pub struct CustomValidator {
pub name: String,
pub message: Option<String>,
/* private fields */
}
Expand description
Custom validator that accepts user-defined validation functions
Fields§
§name: String
Name/identifier for this custom validator
message: Option<String>
Custom error message
Implementations§
Source§impl CustomValidator
impl CustomValidator
Source§impl CustomValidator
Helper functions for common custom validations
impl CustomValidator
Helper functions for common custom validations
Sourcepub fn one_of(name: impl Into<String>, allowed_values: Vec<String>) -> Self
pub fn one_of(name: impl Into<String>, allowed_values: Vec<String>) -> Self
Create a validator that checks if a string is one of the allowed values
Sourcepub fn not_one_of(
name: impl Into<String>,
forbidden_values: Vec<String>,
) -> Self
pub fn not_one_of( name: impl Into<String>, forbidden_values: Vec<String>, ) -> Self
Create a validator that checks if a value is not in a list of forbidden values
Sourcepub fn contains(name: impl Into<String>, substring: String) -> Self
pub fn contains(name: impl Into<String>, substring: String) -> Self
Create a validator that checks if a string contains a specific substring
Sourcepub fn not_contains(name: impl Into<String>, substring: String) -> Self
pub fn not_contains(name: impl Into<String>, substring: String) -> Self
Create a validator that checks if a string does not contain a specific substring
Sourcepub fn starts_with(name: impl Into<String>, prefix: String) -> Self
pub fn starts_with(name: impl Into<String>, prefix: String) -> Self
Create a validator that checks if a string starts with a specific prefix
Sourcepub fn ends_with(name: impl Into<String>, suffix: String) -> Self
pub fn ends_with(name: impl Into<String>, suffix: String) -> Self
Create a validator that checks if a string ends with a specific suffix
Sourcepub fn array_length(name: impl Into<String>, expected_length: usize) -> Self
pub fn array_length(name: impl Into<String>, expected_length: usize) -> Self
Create a validator that checks if an array has a specific length
Trait Implementations§
Source§impl Clone for CustomValidator
impl Clone for CustomValidator
Source§fn clone(&self) -> CustomValidator
fn clone(&self) -> CustomValidator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CustomValidator
impl Debug for CustomValidator
Source§impl ValidationRule for CustomValidator
impl ValidationRule for CustomValidator
Source§fn validate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
value: &'life1 Value,
field: &'life2 str,
) -> Pin<Box<dyn Future<Output = ValidationResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn validate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
value: &'life1 Value,
field: &'life2 str,
) -> Pin<Box<dyn Future<Output = ValidationResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Validate a single value
Source§fn parameters(&self) -> Option<Value>
fn parameters(&self) -> Option<Value>
Get validation rule parameters/configuration as JSON
Auto Trait Implementations§
impl Freeze for CustomValidator
impl !RefUnwindSafe for CustomValidator
impl Send for CustomValidator
impl Sync for CustomValidator
impl Unpin for CustomValidator
impl !UnwindSafe for CustomValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more