pub struct UniqueItemsRule {
pub message: Option<String>,
}Expand description
Unique items validation rule - all items in a collection must be unique.
§Example
use skp_validator_rules::collection::unique_items::UniqueItemsRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = UniqueItemsRule::new();
let ctx = ValidationContext::default();
assert!(rule.validate(&vec!["a", "b", "c"], &ctx).is_ok());
assert!(rule.validate(&vec!["a", "b", "a"], &ctx).is_err());Fields§
§message: Option<String>Custom error message
Implementations§
Trait Implementations§
Source§impl Clone for UniqueItemsRule
impl Clone for UniqueItemsRule
Source§fn clone(&self) -> UniqueItemsRule
fn clone(&self) -> UniqueItemsRule
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 UniqueItemsRule
impl Debug for UniqueItemsRule
Source§impl Default for UniqueItemsRule
impl Default for UniqueItemsRule
Source§fn default() -> UniqueItemsRule
fn default() -> UniqueItemsRule
Returns the “default value” for a type. Read more
Source§impl<T: Eq + Hash> Rule<[T]> for UniqueItemsRule
impl<T: Eq + Hash> Rule<[T]> for UniqueItemsRule
Source§fn validate(
&self,
value: &[T],
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &[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<T: Eq + Hash> Rule<Vec<T>> for UniqueItemsRule
impl<T: Eq + Hash> Rule<Vec<T>> for UniqueItemsRule
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).
Auto Trait Implementations§
impl Freeze for UniqueItemsRule
impl RefUnwindSafe for UniqueItemsRule
impl Send for UniqueItemsRule
impl Sync for UniqueItemsRule
impl Unpin for UniqueItemsRule
impl UnwindSafe for UniqueItemsRule
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