[−][src]Trait aragog::Validate
The Validate
trait of the Aragog library.
This trait provides the possibility to validate an instance or its fields formats or logic. Its main use
it to validate a new or updated Record
model instance before saving it.
Required methods
fn validations(&self, errors: &mut Vec<String>)
Runs all the defined validation on fields and fills the errors
string vector with custom error messages
Provided methods
fn validate(&self) -> Result<(), ServiceError>
Validates the object field formats, logic or anything. Calls the validations
method
and will render a complete ServiceError
::ValidationError
on validation failure.
On success returns ()
fn is_valid(&self) -> bool
Runs all validations and returns a false
if they failed, on success true
is returned
fn validate_field_presence<T>(
field_name: &str,
field: &Option<T>,
errors: &mut Vec<String>
) -> bool
field_name: &str,
field: &Option<T>,
errors: &mut Vec<String>
) -> bool
Helper function to simply check the presence of a field. This function is usually used inside the
validations
method since it will fill the errors
with a message if the field
is missing.
Arguments
field_name
- The string slice name of the field, will be used in the error message on failurefield
- Optional value, iffield
isSome<T>
the function will succeederrors
- the mutable reference of the error message vector like provided invalidations
Returns
true
if field
is Some<T>
on failure, false
is returned and errors
stored a new message
fn validate_field_absence<T>(
field_name: &str,
field: &Option<T>,
errors: &mut Vec<String>
) -> bool
field_name: &str,
field: &Option<T>,
errors: &mut Vec<String>
) -> bool
Helper function to simply check the absence of a field. This function is usually used inside the
validations
method since it will fill the errors
with a message if the field
is missing.
Arguments
field_name
- The string slice name of the field, will be used in the error message on failurefield
- Optional value, iffield
isNone
the function will succeederrors
- the mutable reference of the error message vector like provided invalidations
Returns
true
if field
is None
on failure, false
is returned and errors
stored a new message