pub struct VersionInformation {
pub major: i32,
pub minor: i32,
pub build: i32,
pub hash: String,
}Expand description
Holds the data structure and implementation for retrieving and storing version information of the application.
Fields§
§major: i32Major version number (used to identify major changes between releases)
minor: i32Minor version number (used to identify minor changes between releases)
build: i32Build number (increases with every published build)
hash: StringHash serves as a fingerprint to match SW with database configuration
Implementations§
Source§impl VersionInformation
impl VersionInformation
Sourcepub fn new() -> Result<VersionInformation, VersionInformationError>
pub fn new() -> Result<VersionInformation, VersionInformationError>
Creates a new VersionInformation instance by reading the version from
Cargo.toml at compile time and calculating the SHA-256 hash of the
current executable.
This is the primary constructor for production use. It performs the following steps:
- Retrieves the package version string (e.g., “1.2.3”) from the
CARGO_PKG_VERSIONenvironment variable, which Cargo sets at compile time. - Determines the full path to the running executable.
- Reads the executable file’s binary content.
- Calculates a SHA-256 hash of the binary content to serve as a unique fingerprint.
- Parses the version string and combines it with the hash.
§Returns
A Result containing a new VersionInformation struct on success.
§Errors
Returns a VersionInformationError if any part of the process fails:
VersionInformationError::CurrentExecutablePathRetrievalFailure: If the path to the current executable cannot be determined.VersionInformationError::ExecutableFileReadFailure: If the executable file cannot be read from the filesystem, which could be due to a permissions issue.- It will also propagate any parsing or conversion errors from the underlying
from_string_and_hashfunction if the version string fromCargo.tomlis malformed.
Sourcepub fn from_string_and_hash(
version_string: String,
hash: String,
) -> Result<VersionInformation, VersionInformationError>
pub fn from_string_and_hash( version_string: String, hash: String, ) -> Result<VersionInformation, VersionInformationError>
Creates a new VersionInformation instance from a version string and a hash.
This function is designed to be used in testing environments, allowing for the injection of arbitrary version strings and hashes to validate parsing and behavior.
§Arguments
version_string- A string slice representing the version (e.g., “1.2.3”).hash- TheStringto use for the hash value.
§Returns
A Result containing a new VersionInformation struct, or a VersionInformationError
if the version string cannot be parsed.
Trait Implementations§
Source§impl Display for VersionInformation
impl Display for VersionInformation
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the VersionInformation for display.
This implementation provides a human-readable, multi-line representation of the version details, including major, minor, build numbers, and the executable hash.
§Arguments
f- A mutable reference to aFormatterwhere the output will be written.
§Returns
An Ok(()) on successful formatting.
§Errors
Returns an Err containing a std::fmt::Error if an I/O error occurs
while writing to the formatter.