Skip to main content

validate_time_unit

Function validate_time_unit 

Source
pub fn validate_time_unit(time_unit: &str) -> Result<Option<&str>, Error>
Expand description

Validates the time unit string and returns an optional normalized time unit.

§Arguments

  • time_unit - A string representing the time unit to validate.

§Returns

  • Ok(None) if an empty string is provided
  • Ok(Some(time_unit)) if the time unit is ‘MILLISECOND’, ‘MICROSECOND’, ‘millisecond’, or ‘microsecond’
  • Err with an error message if an invalid time unit is provided

§Errors

Returns Err(anyhow::Error) if time_unit is non-empty and not one of the allowed values.

§Examples

let result = validate_time_unit("MILLISECOND“); assert!(result.is_ok());

let result = validate_time_unit(“”); assert!(result.is_ok() && result.unwrap().is_none());

let result = validate_time_unit("SECOND“); assert!(result.is_err());