ValidateErrorCollector

Struct ValidateErrorCollector 

Source
pub struct ValidateErrorCollector(pub Vec<(String, Box<dyn LocaleMessage>)>);
Expand description

A struct for collecting validation errors in a list.

ValidateErrorCollector is used to gather validation errors that can be associated with a specific field or key. Each error is stored as a tuple containing:

  • A String representing the field or key name where the error occurred.
  • A Box<dyn LocaleMessage> representing a localized error message.

§Fields

  • 0: A vector of tuples, each tuple containing a field name as String and a localized error message as Box<dyn LocaleMessage>.

Note: The LocaleMessage trait is used to encapsulate errors with localization support. Implementations of LocaleMessage should provide mechanisms for translating error messages to various locales.

Tuple Fields§

§0: Vec<(String, Box<dyn LocaleMessage>)>

Implementations§

Source§

impl ValidateErrorCollector

Source

pub fn new() -> Self

Creates a new instance of the struct with an empty Vec.

§Returns

A new instance of the struct containing an empty Vec.

§Examples
use cjtoolkit_structured_validator::common::locale::ValidateErrorCollector;
let instance = ValidateErrorCollector::new();
assert!(instance.0.is_empty());
Source

pub fn is_empty(&self) -> bool

Checks whether the container is empty.

This method returns true if the container has no elements, and false otherwise.

§Returns
  • true - If the container is empty.
  • false - If the container contains one or more elements.
§Examples
use cjtoolkit_structured_validator::common::locale::ValidateErrorCollector;
let container = ValidateErrorCollector::new();
assert!(container.is_empty());
Source

pub fn push(&mut self, error: (String, Box<dyn LocaleMessage>))

Adds an error item to the collection.

§Parameters
  • error: A tuple containing:
    • A String representing the error message or identifier.
    • A Box<dyn LocaleMessage> which encapsulates a trait object implementing LocaleMessage. This provides localized details for the error.
§Behavior

Appends the given error tuple to the internal vector storing errors.

Source

pub fn len(&self) -> usize

Returns the number of elements in the collection.

This method provides the length of the underlying collection by delegating the call to the .len() method of the inner data structure.

§Returns
  • usize - The number of elements currently contained in the collection.

Trait Implementations§

Source§

impl Default for ValidateErrorCollector

Source§

fn default() -> ValidateErrorCollector

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

impl Into<ValidateErrorCollector> for ValidateErrorStore

Source§

fn into(self) -> ValidateErrorCollector

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

impl Into<ValidateErrorStore> for ValidateErrorCollector

Source§

fn into(self) -> ValidateErrorStore

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,