RuleBuilder

Struct RuleBuilder 

Source
pub struct RuleBuilder<T> { /* private fields */ }
Expand description

Builder for creating validation rules in a fluent style

Implementations§

Source§

impl<T> RuleBuilder<T>

Source

pub fn for_property(property_name: impl Into<String>) -> Self

Create a new rule builder for a property

Source

pub fn rule(self, rule: impl Fn(&T) -> Option<String> + 'static) -> Self

Add a custom rule

Source

pub fn not_empty(self, message: Option<impl Into<String>>) -> Self
where T: AsRef<str>,

Validate that the value is not empty (for strings)

§Arguments
  • message - Optional custom error message. If not provided, uses default message.
Source

pub fn not_null(self, message: Option<impl Into<String>>) -> Self
where T: OptionLike,

Validate that the value is not null/empty (for Option types)

§Arguments
  • message - Optional custom error message. If not provided, uses default message.
Source

pub fn min_length( self, min: usize, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: AsRef<str>,

Validate minimum length

§Arguments
  • min - Minimum length required
  • message - Optional custom error message. If not provided, uses default message with the min value.
Source

pub fn max_length( self, max: usize, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: AsRef<str>,

Validate maximum length

§Arguments
  • max - Maximum length allowed
  • message - Optional custom error message. If not provided, uses default message with the max value.
Source

pub fn length( self, min: usize, max: usize, min_message: Option<impl Into<String> + Clone + 'static>, max_message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: AsRef<str>,

Validate length range

§Arguments
  • min - Minimum length required
  • max - Maximum length allowed
  • min_message - Optional custom error message for minimum length violation
  • max_message - Optional custom error message for maximum length violation
Source

pub fn email(self, message: Option<impl Into<String>>) -> Self
where T: AsRef<str>,

Validate email format

§Arguments
  • message - Optional custom error message. If not provided, uses default message.
Source

pub fn greater_than( self, min: impl Into<f64> + Copy + 'static, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: Numeric,

Validate that value is greater than a minimum

§Arguments
  • min - Minimum value (exclusive)
  • message - Optional custom error message. If not provided, uses default message with the min value.
Source

pub fn greater_than_or_equal( self, min: impl Into<f64> + Copy + 'static, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: Numeric,

Validate that value is greater than or equal to a minimum

§Arguments
  • min - Minimum value (inclusive)
  • message - Optional custom error message. If not provided, uses default message with the min value.
Source

pub fn less_than( self, max: impl Into<f64> + Copy + 'static, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: Numeric,

Validate that value is less than a maximum

§Arguments
  • max - Maximum value (exclusive)
  • message - Optional custom error message. If not provided, uses default message with the max value.
Source

pub fn less_than_or_equal( self, max: impl Into<f64> + Copy + 'static, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: Numeric,

Validate that value is less than or equal to a maximum

§Arguments
  • max - Maximum value (inclusive)
  • message - Optional custom error message. If not provided, uses default message with the max value.
Source

pub fn inclusive_between( self, min: impl Into<f64> + Copy + 'static, max: impl Into<f64> + Copy + 'static, message: Option<impl Into<String> + Clone + 'static>, ) -> Self
where T: Numeric,

Validate that value is within a range (inclusive)

§Arguments
  • min - Minimum value (inclusive)
  • max - Maximum value (inclusive)
  • message - Optional custom error message. If not provided, uses default message with the min and max values.
Source

pub fn must( self, predicate: impl Fn(&T) -> bool + 'static, message: impl Into<String> + Clone + 'static, ) -> Self

Validate with a custom predicate

Source

pub fn build(self) -> impl Fn(&T) -> Vec<ValidationError>

Build the rule and return a function that can be used in a validator

Auto Trait Implementations§

§

impl<T> Freeze for RuleBuilder<T>

§

impl<T> !RefUnwindSafe for RuleBuilder<T>

§

impl<T> !Send for RuleBuilder<T>

§

impl<T> !Sync for RuleBuilder<T>

§

impl<T> Unpin for RuleBuilder<T>

§

impl<T> !UnwindSafe for RuleBuilder<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.