Struct promkit::validate::ValidatorManager

source ·
pub struct ValidatorManager<T: ?Sized> { /* private fields */ }
Expand description

A generic structure for validating inputs of any type.

This structure allows for the definition of custom validation logic and error message generation for inputs of a specified type. It encapsulates a validator function and an error message generator function, both of which operate on references to the input.

Implementations§

source§

impl<T: ?Sized> ValidatorManager<T>

source

pub fn new( validator: Validator<T>, error_message_generator: ErrorMessageGenerator<T> ) -> Self

Constructs a new Validator instance with the specified validator and error message generator functions.

§Arguments
  • validator - A function that takes a reference to an input of type T and returns a boolean indicating whether the input passes the validation.
  • error_message_generator - A function that takes a reference to an input of type T and returns a String that describes the validation error.
§Returns

Returns a new instance of Validator<T>.

source

pub fn validate(&self, input: &T) -> bool

Validates the given input using the encapsulated validator function.

§Arguments
  • input - A reference to the input of type T to be validated.
§Returns

Returns true if the input passes the validation, otherwise false.

source

pub fn generate_error_message(&self, input: &T) -> String

Generates an error message for the given input using the encapsulated error message generator function.

§Arguments
  • input - A reference to the input of type T for which to generate an error message.
§Returns

Returns a String that describes the validation error.

Auto Trait Implementations§

§

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

§

impl<T> RefUnwindSafe for ValidatorManager<T>
where T: ?Sized,

§

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

§

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

§

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

§

impl<T> UnwindSafe for ValidatorManager<T>
where T: ?Sized,

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>,

§

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>,

§

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.