Struct VersionInformation

Source
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: i32

Major version number (used to identify major changes between releases)

§minor: i32

Minor version number (used to identify minor changes between releases)

§build: i32

Build number (increases with every published build)

§hash: String

Hash serves as a fingerprint to match SW with database configuration

Implementations§

Source§

impl VersionInformation

Source

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:

  1. Retrieves the package version string (e.g., “1.2.3”) from the CARGO_PKG_VERSION environment variable, which Cargo sets at compile time.
  2. Determines the full path to the running executable.
  3. Reads the executable file’s binary content.
  4. Calculates a SHA-256 hash of the binary content to serve as a unique fingerprint.
  5. 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_hash function if the version string from Cargo.toml is malformed.
Source

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 - The String to 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

Source§

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 a Formatter where 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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T