uefi_raw/table/
revision.rs1use core::fmt;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
34#[repr(transparent)]
35pub struct Revision(pub u32);
36
37#[allow(missing_docs)]
40impl Revision {
41 pub const EFI_1_02: Self = Self::new(1, 2);
42 pub const EFI_1_10: Self = Self::new(1, 10);
43 pub const EFI_2_00: Self = Self::new(2, 00);
44 pub const EFI_2_10: Self = Self::new(2, 10);
45 pub const EFI_2_20: Self = Self::new(2, 20);
46 pub const EFI_2_30: Self = Self::new(2, 30);
47 pub const EFI_2_31: Self = Self::new(2, 31);
48 pub const EFI_2_40: Self = Self::new(2, 40);
49 pub const EFI_2_50: Self = Self::new(2, 50);
50 pub const EFI_2_60: Self = Self::new(2, 60);
51 pub const EFI_2_70: Self = Self::new(2, 70);
52 pub const EFI_2_80: Self = Self::new(2, 80);
53 pub const EFI_2_90: Self = Self::new(2, 90);
54 pub const EFI_2_100: Self = Self::new(2, 100);
55}
56
57impl Revision {
58 #[must_use]
60 pub const fn new(major: u16, minor: u16) -> Self {
61 let major = major as u32;
62 let minor = minor as u32;
63 let value = (major << 16) | minor;
64 Self(value)
65 }
66
67 #[must_use]
69 pub const fn major(self) -> u16 {
70 (self.0 >> 16) as u16
71 }
72
73 #[must_use]
75 pub const fn minor(self) -> u16 {
76 self.0 as u16
77 }
78}
79
80impl fmt::Display for Revision {
81 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82 let (major, minor) = (self.major(), self.minor());
83
84 if major < 2 {
85 write!(f, "{major}.{minor:02}")
86 } else {
87 let (minor, patch) = (minor / 10, minor % 10);
88 if patch == 0 {
89 write!(f, "{major}.{minor}")
90 } else {
91 write!(f, "{major}.{minor}.{patch}")
92 }
93 }
94 }
95}
96
97#[cfg(test)]
98mod tests {
99 use super::*;
100
101 #[test]
102 fn test_revision() {
103 let rev = Revision::EFI_2_31;
104 assert_eq!(rev.major(), 2);
105 assert_eq!(rev.minor(), 31);
106 assert_eq!(rev.0, 0x0002_001f);
107
108 assert!(Revision::EFI_1_10 < Revision::EFI_2_00);
109 }
110}