cargo-pkg-info-struct-builder 0.1.0-alpha7

A Rust crate used as a build dependency which provides structured access to Cargo Package Info.
Documentation
//------------------------------------------------------------------------------
// This file is automatically generated by `cargo-pkg-info-struct-builder`.
//
// DO NOT EDIT THIS FILE MANUALLY. ANY CHANGES WILL BE OVERWRITTEN.
//
// It contains a struct `CargoPkgInfo` that provides access to package metadata
// set by Cargo at compile time, including versioning, authors, license
// information, and build details. The values are obtained from environment
// variables defined in the Cargo.toml file and passed during the build process.
//
// For more information, see: <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
//------------------------------------------------------------------------------

pub struct CargoPkgInfo {}

/// Unescapes all `\\n` sequences back to `\n`.
macro_rules! unescape_newlines {
    ($s:expr) => {
        Box::leak($s.replace("\\n", "\n").into_boxed_str())
    };
}

impl CargoPkgInfo {
    /// Returns the package name.
    #[allow(dead_code)]
    pub fn pkg_name() -> Option<&'static str> {
        option_env!("CARGO_PKG_NAME")
    }

    /// Returns the crate name.
    #[allow(dead_code)]
    pub fn crate_name() -> Option<&'static str> {
        option_env!("CARGO_CRATE_NAME")
    }

    /// Returns the package version.
    #[allow(dead_code)]
    pub fn pkg_version() -> Option<&'static str> {
        option_env!("CARGO_PKG_VERSION")
    }

    /// Returns the major version of the package.
    #[allow(dead_code)]
    pub fn version_major() -> Option<&'static str> {
        option_env!("CARGO_PKG_VERSION_MAJOR")
    }

    /// Returns the major version of the package as a number.
    #[allow(dead_code)]
    pub fn version_major_numeric() -> Option<u32> {
        option_env!("CARGO_PKG_VERSION_MAJOR").and_then(|s| s.parse().ok())
    }

    /// Returns the minor version of the package.
    #[allow(dead_code)]
    pub fn version_minor() -> Option<&'static str> {
        option_env!("CARGO_PKG_VERSION_MINOR")
    }

    /// Returns the minor version of the package as a number.
    #[allow(dead_code)]
    pub fn version_minor_numeric() -> Option<u32> {
        option_env!("CARGO_PKG_VERSION_MINOR").and_then(|s| s.parse().ok())
    }

    /// Returns the patch version of the pacakge.
    #[allow(dead_code)]
    pub fn version_patch() -> Option<&'static str> {
        option_env!("CARGO_PKG_VERSION_PATCH")
    }

    /// Returns the patch version of the pacakge as a number.
    #[allow(dead_code)]
    pub fn version_patch_numeric() -> Option<u32> {
        option_env!("CARGO_PKG_VERSION_PATCH").and_then(|s| s.parse().ok())
    }

    /// Returns the pre-release version of the package.
    #[allow(dead_code)]
    pub fn version_pre() -> Option<&'static str> {
        option_env!("CARGO_PKG_VERSION_PRE")
    }

    /// Returns the authors of the package.
    #[allow(dead_code)]
    pub fn authors() -> Option<&'static str> {
        option_env!("CARGO_PKG_AUTHORS")
    }

    /// Returns the description of the package.
    #[allow(dead_code)]
    pub fn description() -> Option<&'static str> {
        option_env!("CARGO_PKG_DESCRIPTION")
    }

    /// Returns the homepage URL of the package.
    #[allow(dead_code)]
    pub fn homepage() -> Option<&'static str> {
        option_env!("CARGO_PKG_HOMEPAGE")
    }

    /// Returns the repository URL of the package.
    #[allow(dead_code)]
    pub fn repository() -> Option<&'static str> {
        option_env!("CARGO_PKG_REPOSITORY")
    }

    /// Returns the license type of the package.
    #[allow(dead_code)]
    pub fn license() -> Option<&'static str> {
        option_env!("CARGO_PKG_LICENSE")
    }

    /// Returns the contents of the license file (embedded at build time).
    #[allow(dead_code)]
    pub fn license_content() -> Option<&'static str> {
        let license = option_env!("LICENSE_CONTENT");

        if license.is_none() {
            return None;
        }

        Some(unescape_newlines!(license.unwrap()))
    }

    /// Returns the Rust version required by the package.
    #[allow(dead_code)]
    pub fn rust_version() -> Option<&'static str> {
        option_env!("CARGO_PKG_RUST_VERSION")
    }

    /// Returns the path to the README file.
    #[allow(dead_code)]
    pub fn readme_path() -> Option<&'static str> {
        option_env!("CARGO_PKG_README")
    }

    /// Returns the build target (architecture/platform).
    #[allow(dead_code)]
    pub fn build_target() -> Option<&'static str> {
        option_env!("BUILD_TARGET")
    }

    /// Returns the UTC build time as an `Option<u64>`.
    #[allow(dead_code)]
    pub fn build_time_utc() -> Option<u64> {
        option_env!("BUILD_TIME_UTC").and_then(|s| s.parse::<u64>().ok())
    }
}