pub struct RequiredRule {
pub message: Option<String>,
}Expand description
Required validation rule - field must not be empty/null.
§Example
use skp_validator_rules::comparison::required::RequiredRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = RequiredRule::new();
let ctx = ValidationContext::default();
assert!(rule.validate("hello", &ctx).is_ok());
assert!(rule.validate("", &ctx).is_err()); // Empty stringFields§
§message: Option<String>Custom error message
Implementations§
Trait Implementations§
Source§impl Clone for RequiredRule
impl Clone for RequiredRule
Source§fn clone(&self) -> RequiredRule
fn clone(&self) -> RequiredRule
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 RequiredRule
impl Debug for RequiredRule
Source§impl Default for RequiredRule
impl Default for RequiredRule
Source§fn default() -> RequiredRule
fn default() -> RequiredRule
Returns the “default value” for a type. Read more
Source§impl<T> Rule<Option<T>> for RequiredRule
impl<T> Rule<Option<T>> for RequiredRule
Source§fn validate(
&self,
value: &Option<T>,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &Option<T>, _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<String> for RequiredRule
impl Rule<String> for RequiredRule
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<T> Rule<Vec<T>> for RequiredRule
impl<T> Rule<Vec<T>> for RequiredRule
Source§fn validate(
&self,
value: &Vec<T>,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &Vec<T>, _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 RequiredRule
impl Rule<str> for RequiredRule
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 RequiredRule
impl RefUnwindSafe for RequiredRule
impl Send for RequiredRule
impl Sync for RequiredRule
impl Unpin for RequiredRule
impl UnwindSafe for RequiredRule
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