pub struct AllowedValuesRule<T> {
pub values: Vec<T>,
pub message: Option<String>,
}Expand description
Allowed values validation rule - field must be one of the specified values.
§Example
use skp_validator_rules::comparison::allowed_values::AllowedValuesRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = AllowedValuesRule::new(vec!["active", "pending", "disabled"]);
let ctx = ValidationContext::default();
assert!(rule.validate("active", &ctx).is_ok());
assert!(rule.validate("unknown", &ctx).is_err());Fields§
§values: Vec<T>The allowed values
message: Option<String>Custom error message
Implementations§
Source§impl<T> AllowedValuesRule<T>
impl<T> AllowedValuesRule<T>
Trait Implementations§
Source§impl<T: Clone> Clone for AllowedValuesRule<T>
impl<T: Clone> Clone for AllowedValuesRule<T>
Source§fn clone(&self) -> AllowedValuesRule<T>
fn clone(&self) -> AllowedValuesRule<T>
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<T: Debug> Debug for AllowedValuesRule<T>
impl<T: Debug> Debug for AllowedValuesRule<T>
Source§impl Rule<String> for AllowedValuesRule<String>
impl Rule<String> for AllowedValuesRule<String>
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<f64> for AllowedValuesRule<f64>
impl Rule<f64> for AllowedValuesRule<f64>
Source§fn validate(
&self,
value: &f64,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &f64, _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<i32> for AllowedValuesRule<i32>
impl Rule<i32> for AllowedValuesRule<i32>
Source§fn validate(
&self,
value: &i32,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &i32, _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<i64> for AllowedValuesRule<i64>
impl Rule<i64> for AllowedValuesRule<i64>
Source§fn validate(
&self,
value: &i64,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &i64, _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 AllowedValuesRule<&str>
impl Rule<str> for AllowedValuesRule<&str>
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).
Source§impl Rule<str> for AllowedValuesRule<String>
impl Rule<str> for AllowedValuesRule<String>
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).
Source§impl Rule<u32> for AllowedValuesRule<u32>
impl Rule<u32> for AllowedValuesRule<u32>
Source§fn validate(
&self,
value: &u32,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &u32, _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<u64> for AllowedValuesRule<u64>
impl Rule<u64> for AllowedValuesRule<u64>
Source§fn validate(
&self,
value: &u64,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &u64, _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<T> Freeze for AllowedValuesRule<T>
impl<T> RefUnwindSafe for AllowedValuesRule<T>where
T: RefUnwindSafe,
impl<T> Send for AllowedValuesRule<T>where
T: Send,
impl<T> Sync for AllowedValuesRule<T>where
T: Sync,
impl<T> Unpin for AllowedValuesRule<T>where
T: Unpin,
impl<T> UnwindSafe for AllowedValuesRule<T>where
T: UnwindSafe,
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