ContextualRule

Struct ContextualRule 

Source
pub struct ContextualRule<T>
where T: ?Sized,
{ pub rule_name: String, pub condition: Option<ContextualCondition>, pub validator: Option<ContextualValidator<T>>, pub message: Option<String>, }

Fields§

§rule_name: String

Rule name

§condition: Option<ContextualCondition>

Condition function - when to apply validation

§validator: Option<ContextualValidator<T>>

Validation function

§message: Option<String>

Custom error message

Implementations§

Source§

impl<T: ?Sized> ContextualRule<T>

Source

pub fn new(name: impl Into<String>) -> Self

Create a new contextual rule.

Source

pub fn when<F>(self, condition: F) -> Self
where F: Fn(&ValidationContext) -> bool + Send + Sync + 'static,

Set condition for when to apply validation.

Source

pub fn validate_with<F>(self, validator: F) -> Self
where F: Fn(&T, &ValidationContext) -> bool + Send + Sync + 'static,

Set the validation function.

Source

pub fn message(self, msg: impl Into<String>) -> Self

Set custom error message.

Trait Implementations§

Source§

impl<T: ?Sized> Debug for ContextualRule<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized + 'static> Rule<T> for ContextualRule<T>

Source§

fn validate(&self, value: &T, ctx: &ValidationContext) -> ValidationResult<()>

Validate the value.
Source§

fn name(&self) -> &'static str

Get the rule name for error reporting.
Source§

fn default_message(&self) -> String

Get the default error message.
Source§

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

Get the error code.
Source§

fn is_transform(&self) -> bool

Check if this rule is a transformation (not validation).

Auto Trait Implementations§

§

impl<T> Freeze for ContextualRule<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for ContextualRule<T>

§

impl<T> Send for ContextualRule<T>
where T: ?Sized,

§

impl<T> Sync for ContextualRule<T>
where T: ?Sized,

§

impl<T> Unpin for ContextualRule<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for ContextualRule<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.