unleash_api_client/
version.rs

1//! Managing SDK versions
2//!
3//! This module includes utilities to handle versioning aspects used internally
4//! by the crate.
5use std::env;
6
7/// Returns the version of the `unleash-rust-sdk` SDK compiled into the binary.
8///
9/// The version number is included at compile time using the cargo package version
10/// and is formatted as "unleash-rust-sdk:X.Y.Z", where X.Y.Z is the semantic
11/// versioning format. This ensures a consistent versioning approach that aligns
12/// with other Unleash SDKs.
13pub(crate) fn get_sdk_version() -> &'static str {
14    concat!("unleash-rust-sdk:", env!("CARGO_PKG_VERSION"))
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20    use regex::Regex;
21
22    #[test]
23    fn test_get_sdk_version_with_version_set() {
24        let version_output = get_sdk_version();
25        let version_regex = Regex::new(r"^unleash-rust-sdk:\d+\.\d+\.\d+$").unwrap();
26        assert!(
27            version_regex.is_match(version_output),
28            "Version output did not match expected format: {version_output}"
29        );
30    }
31}