Struct RulesBuilder

Source
pub struct RulesBuilder { /* private fields */ }
Expand description

Builder for creating common validation rule combinations

Implementations§

Source§

impl RulesBuilder

Source

pub fn new() -> Self

Create a new rules builder

Source

pub fn build(self) -> Rules

Build and return the rules

Source

pub fn required_string( self, field: impl Into<String>, min_length: Option<usize>, max_length: Option<usize>, ) -> Self

Add validation rules for a required string field

Source

pub fn required_email(self, field: impl Into<String>) -> Self

Add validation rules for a required email field

Source

pub fn optional_email(self, field: impl Into<String>) -> Self

Add validation rules for an optional email field

Source

pub fn required_number( self, field: impl Into<String>, min: Option<f64>, max: Option<f64>, ) -> Self

Add validation rules for a required numeric field

Source

pub fn required_integer( self, field: impl Into<String>, min: Option<f64>, max: Option<f64>, ) -> Self

Add validation rules for a required integer field

Source

pub fn pattern(self, field: impl Into<String>, pattern: &str) -> Self

Add validation rules for a field that must match a pattern

Source

pub fn one_of( self, field: impl Into<String>, allowed_values: Vec<String>, ) -> Self

Add validation rules for a field that must be one of the allowed values

Source

pub fn custom<R>(self, field: impl Into<String>, rule: R) -> Self
where R: ValidationRule + 'static,

Add a custom validation rule

Source

pub fn request_rule<R>(self, rule: R) -> Self
where R: ValidationRule + 'static,

Add a request-level validation rule

Trait Implementations§

Source§

impl Default for RulesBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CreateValidationError for T

Source§

fn validation_error(field: &str, message: &str) -> ValidationError

Source§

fn validation_error_with_code( field: &str, message: &str, code: &str, ) -> ValidationError

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.