StringMandatoryRules

Struct StringMandatoryRules 

Source
pub struct StringMandatoryRules {
    pub is_mandatory: bool,
}
Expand description

A struct representing rules for mandatory string fields.

This struct is designed to hold the configuration for whether a particular string field is mandatory or optional. It provides a simple boolean flag indicating the “mandatory” nature of the string.

§Fields

  • is_mandatory
    • A boolean field that determines whether the string is mandatory.
    • When set to true, the associated string must be provided.
    • When set to false, the associated string is optional.

§Traits

  • The Default trait is implemented for this struct, allowing you to create a default instance where is_mandatory is set to false.

Fields§

§is_mandatory: bool

Implementations§

Source§

impl StringMandatoryRules

Source

pub fn check( &self, messages: &mut ValidateErrorCollector, subject: &StringValidator<'_>, )

Validates a string based on the provided StringValidator and collects validation errors.

§Parameters
  • messages: A mutable reference to a ValidateErrorCollector that accumulates validation errors encountered during the check.
  • subject: A reference to a StringValidator representing the string to be validated.
§Behavior
  • If the self.is_mandatory field is true and the subject is empty, an error message with the text "Cannot be empty" is pushed into the messages collector along with a locale identifier (StringMandatoryLocale).
§Example
use cjtoolkit_structured_validator::common::locale::ValidateErrorCollector;
use cjtoolkit_structured_validator::common::string_validator::StrValidationExtension;
use cjtoolkit_structured_validator::base::string_rules::StringMandatoryRules;
let mut messages = ValidateErrorCollector::new();
let validator = StringMandatoryRules { is_mandatory: true };
let subject = "".as_string_validator();

validator.check(&mut messages, &subject);

assert_eq!(messages.len(), 1); // If the subject is empty and is_mandatory is true, an error will be collected.

Trait Implementations§

Source§

impl Default for StringMandatoryRules

Source§

fn default() -> StringMandatoryRules

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

impl Into<StringMandatoryRules> for &EmailRules

Available on crate feature email only.
Source§

fn into(self) -> StringMandatoryRules

Converts this type into the (usually inferred) input type.
Source§

impl Into<StringMandatoryRules> for &UrlRules

Available on crate feature url only.
Source§

fn into(self) -> StringMandatoryRules

Converts this type into the (usually inferred) input type.

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> 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,