validate

Function validate 

Source
pub fn validate<T, F, S>(value: T, validator: F, message: S) -> CoreResult<T>
where F: FnOnce(&T) -> bool, S: Into<String>,
Expand description

Checks if a value is valid according to a validator function

§Arguments

  • value - The value to validate
  • validator - A function that returns true if the value is valid
  • message - The error message if the value is invalid

§Returns

  • Ok(value) if the value is valid
  • Err(CoreError::ValidationError) if the value is invalid

§Errors

Returns CoreError::ValidationError if the validator function returns false.