pub fn assert_version(
user_version: Option<Version>,
current_version: Option<Version>,
) -> Result<(), String>
Expand description
Asserts the validity of a given user version against the required version. This function checks if the provided user version matches the current system version. It is designed to ensure that operations relying on version numbers are executed with the correct versions to prevent issues with compatibility or outdated requests.
§Parameters
user_version
: AnOption<u64>
representing the user-provided version. This can beNone
if the user did not provide a version, orSome(u64)
if a version was provided.current_version
: AnOption<u64>
representing the required system version. This can beNone
which means no specific version requirement is needed.
§Returns
Ok(())
if theuser_version
matches thecurrent_version
or if no specificcurrent_version
is provided.Err(String)
if:- The
user_version
isNone
, indicating no version was provided. The error string will beERROR_NO_VERSION.to_string()
, whereERROR_NO_VERSION
is a constant string describing the error. - The
user_version
does not match thecurrent_version
, indicating either an incorrect or incompatible version. The error string will format to include the error description (from a constantERROR_VERSION_MISMATCH
), the required version, and the provided user version.
- The
§Examples
let current_version = Some(3); // Example version
let user_version = Some(3);
assert_eq!(assert_version(user_version, current_version), Ok(()));
let wrong_version = Some(2);
assert!(assert_version(wrong_version, current_version).is_err());
let no_version = None;
let no_current_version = None;
assert!(assert_version(no_version, no_current_version).is_ok());