const NO_ENV_FALLBACK: &str = "N/A";
pub struct CargoPkgInfo {}
macro_rules! unescape_newlines {
($s:expr) => {
Box::leak($s.replace("\\n", "\n").into_boxed_str())
};
}
impl CargoPkgInfo {
#[allow(dead_code)]
pub fn pkg_name() -> &'static str {
option_env!("CARGO_PKG_NAME")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn crate_name() -> &'static str {
option_env!("CARGO_CRATE_NAME")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn pkg_version() -> &'static str {
option_env!("CARGO_PKG_VERSION")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn version_major() -> &'static str {
option_env!("CARGO_PKG_VERSION_MAJOR")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn version_minor() -> &'static str {
option_env!("CARGO_PKG_VERSION_MINOR")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn version_patch() -> &'static str {
option_env!("CARGO_PKG_VERSION_PATCH")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn version_pre() -> &'static str {
option_env!("CARGO_PKG_VERSION_PRE")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn authors() -> &'static str {
option_env!("CARGO_PKG_AUTHORS")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn description() -> &'static str {
option_env!("CARGO_PKG_DESCRIPTION")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn homepage() -> &'static str {
option_env!("CARGO_PKG_HOMEPAGE")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn repository() -> &'static str {
option_env!("CARGO_PKG_REPOSITORY")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn license() -> &'static str {
option_env!("CARGO_PKG_LICENSE")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn license_content() -> &'static str {
let license = option_env!("LICENSE_CONTENT").unwrap_or(NO_ENV_FALLBACK);
unescape_newlines!(license)
}
#[allow(dead_code)]
pub fn rust_version() -> &'static str {
option_env!("CARGO_PKG_RUST_VERSION")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn readme_path() -> &'static str {
option_env!("CARGO_PKG_README")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn build_target() -> &'static str {
option_env!("BUILD_TARGET")
.unwrap_or(NO_ENV_FALLBACK)
.into()
}
#[allow(dead_code)]
pub fn build_time_utc() -> Option<u64> {
option_env!("BUILD_TIME_UTC").and_then(|s| s.parse::<u64>().ok())
}
}