pub trait ValidationCheck: Sized {
// Required method
fn validate_new(messages: ValidateErrorStore) -> Self;
// Provided method
fn validate_check(messages: ValidateErrorCollector) -> Result<(), Self> { ... }
}
Expand description
A trait for performing validation checks and handling validation-related errors.
This trait provides methods to:
- Create a new validation error instance from an error store.
- Collect and validate errors, returning a result depending on whether any errors are found.
§Associated Types
Self
: The concrete type that implements theValidationCheck
trait, which represents validation errors.
§Required Methods
§validate_new
Creates a new instance of the implementing type using a provided ValidateErrorStore
.
§Parameters
messages
: An instance ofValidateErrorStore
that holds validation error information.
§Returns
Self
: A new instance of the implementing type initialized with the given error messages.
§Provided Methods
§validate_check
Performs a validation check using a ValidateErrorCollector
. If the collector contains errors,
it returns an error wrapped in the implementing type; otherwise, it succeeds with Ok(())
.
§Parameters
messages
: An instance ofValidateErrorCollector
that holds collected validation errors.
§Returns
Ok(())
: If the collector does not contain any errors.Err(Self)
: If the collector contains errors, an error instance of the implementing type is returned.
The default implementation checks if the provided messages
is empty. If it is empty, it returns an Ok(())
.
Otherwise, it converts the messages into a ValidateErrorStore
and creates a new validation error instance using validate_new
.
Required Methods§
fn validate_new(messages: ValidateErrorStore) -> Self
Provided Methods§
fn validate_check(messages: ValidateErrorCollector) -> Result<(), Self>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl ValidationCheck for DescriptionError
impl ValidationCheck for EmailError
Available on crate feature
email
only.impl ValidationCheck for NameError
impl ValidationCheck for FloatError
impl ValidationCheck for IntegerError
impl ValidationCheck for UnsignedError
impl ValidationCheck for PasswordError
impl ValidationCheck for DateError
Available on crate feature
chrono
only.impl ValidationCheck for cjtoolkit_structured_validator::types::times_chrono::date_time::DateTimeError
Available on crate feature
chrono
only.impl ValidationCheck for NaiveDateTimeError
Available on crate feature
chrono
only.impl ValidationCheck for TimeError
Available on crate feature
chrono
only.impl ValidationCheck for cjtoolkit_structured_validator::types::times_humantime::DateTimeError
Available on crate feature
humantime
only.impl ValidationCheck for UrlError
Available on crate feature
url
only.