#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Semver {
major: u8,
minor: u8,
patch: u8,
pre: u8,
}
impl Semver {
pub const fn pack(self) -> u64 {
(self.major as u64) << 24
| (self.minor as u64) << 16
| (self.patch as u64) << 8
| (self.pre as u64)
}
pub const fn unpack(v: u64) -> Self {
Self {
major: (v >> 24) as u8,
minor: (v >> 16) as u8,
patch: (v >> 8) as u8,
pre: v as u8,
}
}
}
impl std::fmt::Display for Semver {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)?;
if self.pre > 0 {
write!(f, "-pre.{}", self.pre)?;
}
Ok(())
}
}
#[allow(unsafe_code)]
#[no_mangle]
#[used]
#[doc(hidden)]
pub static ARK_PACKED_FFI_CRATE_VERSION: u64 = Semver {
major: 0,
minor: 16,
patch: 0,
pre: 0,
}
.pack();
#[cfg(test)]
mod test {
use super::*;
#[test]
#[allow(clippy::panic)]
fn crate_version_match() {
let version = Semver::unpack(ARK_PACKED_FFI_CRATE_VERSION);
let version_str = version.to_string();
if version_str != env!("CARGO_PKG_VERSION") {
panic!("Crate version mismatch, please update ARK_PACKED_FFI_CRATE_VERSION (\"{version_str}\") to be the same as the crate version in `api/api-ffi/Cargo.toml` (\"{}\")", env!("CARGO_PKG_VERSION"));
}
}
}