use core::fmt;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[repr(transparent)]
pub struct Revision(u32);
#[allow(missing_docs)]
impl Revision {
pub const EFI_1_02: Self = Self::new(1, 2);
pub const EFI_1_10: Self = Self::new(1, 10);
pub const EFI_2_00: Self = Self::new(2, 00);
pub const EFI_2_10: Self = Self::new(2, 10);
pub const EFI_2_20: Self = Self::new(2, 20);
pub const EFI_2_30: Self = Self::new(2, 30);
pub const EFI_2_31: Self = Self::new(2, 31);
pub const EFI_2_40: Self = Self::new(2, 40);
pub const EFI_2_50: Self = Self::new(2, 50);
pub const EFI_2_60: Self = Self::new(2, 60);
pub const EFI_2_70: Self = Self::new(2, 70);
pub const EFI_2_80: Self = Self::new(2, 80);
pub const EFI_2_90: Self = Self::new(2, 90);
pub const EFI_2_100: Self = Self::new(2, 100);
}
impl Revision {
#[must_use]
pub const fn new(major: u16, minor: u16) -> Self {
let major = major as u32;
let minor = minor as u32;
let value = (major << 16) | minor;
Revision(value)
}
#[must_use]
pub const fn major(self) -> u16 {
(self.0 >> 16) as u16
}
#[must_use]
pub const fn minor(self) -> u16 {
self.0 as u16
}
}
impl fmt::Display for Revision {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (major, minor) = (self.major(), self.minor());
if major < 2 {
write!(f, "{major}.{minor:02}")
} else {
let (minor, patch) = (minor / 10, minor % 10);
if patch == 0 {
write!(f, "{major}.{minor}")
} else {
write!(f, "{major}.{minor}.{patch}")
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_revision() {
let rev = Revision::EFI_2_31;
assert_eq!(rev.major(), 2);
assert_eq!(rev.minor(), 31);
assert_eq!(rev.0, 0x0002_001f);
assert!(Revision::EFI_1_10 < Revision::EFI_2_00);
}
}