pub struct ContainsRule {
pub substring: String,
pub case_insensitive: bool,
pub message: Option<String>,
}Expand description
Contains validation rule - string must contain a substring.
§Example
use skp_validator_rules::string::contains::ContainsRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = ContainsRule::new("@");
let ctx = ValidationContext::default();
assert!(rule.validate("test@example.com", &ctx).is_ok());
assert!(rule.validate("testexample.com", &ctx).is_err());Fields§
§substring: StringThe substring to search for
case_insensitive: boolCase insensitive matching
message: Option<String>Custom error message
Implementations§
Trait Implementations§
Source§impl Clone for ContainsRule
impl Clone for ContainsRule
Source§fn clone(&self) -> ContainsRule
fn clone(&self) -> ContainsRule
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 ContainsRule
impl Debug for ContainsRule
Source§impl Rule<String> for ContainsRule
impl Rule<String> for ContainsRule
Source§fn validate(
&self,
value: &String,
ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &String, ctx: &ValidationContext, ) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Source§impl Rule<str> for ContainsRule
impl Rule<str> for ContainsRule
Source§fn validate(
&self,
value: &str,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &str, _ctx: &ValidationContext, ) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Auto Trait Implementations§
impl Freeze for ContainsRule
impl RefUnwindSafe for ContainsRule
impl Send for ContainsRule
impl Sync for ContainsRule
impl Unpin for ContainsRule
impl UnwindSafe for ContainsRule
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