StringValidator

Struct StringValidator 

Source
pub struct StringValidator<'a>(/* private fields */);
Expand description

A structure for validating strings with specific constraints.

Implementations§

Source§

impl<'a> StringValidator<'a>

Source

pub const SPECIAL_CHARS: [char; 30]

A constant array that contains a predefined set of 30 special characters.

These special characters are commonly used in programming, input validation, and applications where character-based operations are required, such as parsing, formatting, or password generation.

§Characters included:
  • !, @, #, $, %, ^, &, *, (, ), -, _, =, +
  • [, ], {, }, \, |, ;, :, ', "
  • ,, ., <, >, /, ?
§Notes

This constant is immutable and should be used for read-only.

Source

pub fn count_graphemes(&self) -> usize

Returns the number of graphemes in the structure.

This function retrieves the count of graphemes stored within the current instance. It assumes that the second element of the tuple (self.1) represents the grapheme count.

§Returns
  • usize - The total number of graphemes.
Source

pub fn is_empty(&self) -> bool

Checks whether the current object is empty.

§Returns
  • true if the internal value (self.1) is equal to 0, indicating that the object is empty.
  • false otherwise.
Source

pub fn has_special_chars(&self) -> bool

Checks if the string contains any special character from a predefined set.

§Returns
  • true - If the string contains at least one special character.
  • false - If the string does not contain any special characters.
§Implementation Details
  • Checks each character in the string to determine if it is part of the SPECIAL_CHARS set.
Source

pub fn count_special_chars(&self) -> usize

Counts the number of special characters in the string.

This function iterates through the characters of the string and determines how many of them are considered special. A special character is defined as any character present in the SPECIAL_CHARS set.

§Returns
  • usize - The number of special characters in the string.
§Note
  • The SPECIAL_CHARS set is a pre-defined constant within the implementation of this type, specifying what qualifies as a special character.
Source

pub fn has_ascii_uppercase(&self) -> bool

Checks if the string contains at least one ASCII uppercase character.

§Returns
  • true - If the string contains at least one ASCII uppercase character.
  • false - If the string does not contain any ASCII uppercase characters.
§Note

This function iterates over the characters of the string and checks if any character is an ASCII uppercase letter (i.e., ‘A’ to ‘Z’).

Source

pub fn count_ascii_uppercase(&self) -> usize

Counts and returns the number of ASCII uppercase letters in the string.

§Description

This function iterates over the characters of the string, filters out those that are ASCII uppercase letters, and returns the total count.

§Returns
  • usize - The number of ASCII uppercase letters in the string.
Source

pub fn has_ascii_lowercase(&self) -> bool

Checks if the string slice contains any ASCII lowercase characters.

§Returns
  • true if the string contains at least one ASCII lowercase character ('a-zA-Z').
  • false if no ASCII lowercase characters are found.

This method iterates through all the characters of the inner string (self.0) and checks if any character satisfies the is_ascii_lowercase predicate. It returns as soon as a lowercase ASCII character is found.

Source

pub fn count_ascii_lowercase(&self) -> usize

Counts the number of ASCII lowercase characters in the string.

This function iterates through each character of the string stored in the first field of the tuple (self.0), filters out only those that are lowercase ASCII alphabetic characters (a-z), and returns their count.

§Returns
  • usize - The number of ASCII lowercase characters in the string.

Note: This function only checks for ASCII lowercase characters. Non-ASCII characters are ignored.

Source

pub fn has_ascii_uppercase_and_lowercase(&self) -> bool

Checks if the current object contains both ASCII uppercase and lowercase characters.

This method evaluates whether the instance has at least one ASCII uppercase letter (e.g., ‘A’-‘Z’) and at least one ASCII lowercase letter (e.g., ‘a’-‘z’) simultaneously.

§Returns
  • true - If the instance contains both uppercase and lowercase ASCII characters.
  • false - If the instance does not contain both uppercase and lowercase ASCII characters.
Source

pub fn count_ascii_uppercase_and_lowercase(&self) -> usize

Counts the total number of ASCII uppercase and lowercase characters in the current instance.

This method combines the results of count_ascii_uppercase and count_ascii_lowercase, returning their sum. It provides a convenient way to calculate the total count of ASCII alphabetic characters (both uppercase and lowercase).

§Returns
  • usize - The sum of the ASCII uppercase and lowercase character counts.

Note: The functionality of this method depends on the implementation of both count_ascii_uppercase and count_ascii_lowercase methods, which must be defined elsewhere in the same context.

Source

pub fn has_ascii_digit(&self) -> bool

Checks whether the inner string contains at least one ASCII digit.

§Returns
  • true if the string contains at least one ASCII digit (0-9).
  • false otherwise.

This method works by iterating over the characters of the inner string and checking if any character is an ASCII digit.

Source

pub fn count_ascii_digit(&self) -> usize

Counts the number of ASCII digit characters in the string.

This function iterates through the characters of the string, filters out the characters that are ASCII digits (0-9), and returns the count of those digits.

§Returns
  • usize - The total number of ASCII digit characters in the string.

Note: Non-ASCII digits (e.g., Arabic numerals) will not be counted.

Source

pub fn has_ascii_alphanumeric(&self) -> bool

Checks if the string contains any ASCII alphanumeric characters.

This method checks if at least one character in the string is an ASCII alphanumeric character. ASCII alphanumeric characters are defined as ‘a’ to ‘z’, ‘A’ to ‘Z’, and ‘0’ to ‘9’.

§Returns
  • true - If the string contains at least one ASCII alphanumeric character.
  • false - If the string does not contain any ASCII alphanumeric characters.
Source

pub fn count_ascii_alphanumeric(&self) -> usize

Counts the number of ASCII alphanumeric characters in the string.

This function iterates through the characters of the string, filters out those that are ASCII alphanumeric (letters and digits), and returns the count of such characters.

§Returns
  • usize - The number of ASCII alphanumeric characters in the string.

Note: This function will only count characters that are both ASCII and alphanumeric. Non-ASCII characters or symbols will not be included in the count.

Auto Trait Implementations§

§

impl<'a> Freeze for StringValidator<'a>

§

impl<'a> RefUnwindSafe for StringValidator<'a>

§

impl<'a> Send for StringValidator<'a>

§

impl<'a> Sync for StringValidator<'a>

§

impl<'a> Unpin for StringValidator<'a>

§

impl<'a> UnwindSafe for StringValidator<'a>

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,