[][src]Trait aragog::Validate

pub trait Validate {
    fn validations(&self, errors: &mut Vec<String>);

    fn validate(&self) -> Result<(), ServiceError> { ... }
fn is_valid(&self) -> bool { ... }
fn validate_field_presence<T>(
        field_name: &str,
        field: &Option<T>,
        errors: &mut Vec<String>
    ) -> bool { ... }
fn validate_field_absence<T>(
        field_name: &str,
        field: &Option<T>,
        errors: &mut Vec<String>
    ) -> bool { ... } }

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

Loading content...

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

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 failure
  • field - Optional value, if field is Some<T> the function will succeed
  • errors - the mutable reference of the error message vector like provided in validations

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

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 failure
  • field - Optional value, if field is None the function will succeed
  • errors - the mutable reference of the error message vector like provided in validations

Returns

true if field is None on failure, false is returned and errors stored a new message

Loading content...

Implementors

Loading content...