@@ -6,7 +6,32 @@ use core::fmt;
6
6
///
7
7
/// The minor revision number is incremented on minor changes,
8
8
/// it is stored as a two-digit binary-coded decimal.
9
- #[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd ) ]
9
+ ///
10
+ /// # Display format
11
+ ///
12
+ /// For major revision 2 and later, if the lower minor digit is zero,
13
+ /// the revision is formatted as "major.minor-upper". Otherwise it's
14
+ /// formatted as "major.minor-upper.minor-lower". This format is
15
+ /// described in the "EFI System Table" section of the UEFI
16
+ /// Specification.
17
+ ///
18
+ /// Prior to major version 2, the revision is always formatted as
19
+ /// "major.minor", with minor left-padded with zero if minor-upper is
20
+ /// zero.
21
+ ///
22
+ /// Examples:
23
+ ///
24
+ /// ```
25
+ /// use uefi::table::Revision;
26
+ /// assert_eq!(Revision::EFI_1_02.to_string(), "1.02");
27
+ /// assert_eq!(Revision::EFI_1_10.to_string(), "1.10");
28
+ /// assert_eq!(Revision::EFI_2_00.to_string(), "2.0");
29
+ /// assert_eq!(Revision::EFI_2_30.to_string(), "2.3");
30
+ /// assert_eq!(Revision::EFI_2_31.to_string(), "2.3.1");
31
+ /// assert_eq!(Revision::EFI_2_100.to_string(), "2.10");
32
+ /// ```
33
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd ) ]
34
+ #[ repr( transparent) ]
10
35
pub struct Revision ( u32 ) ;
11
36
12
37
// Allow missing docs, there's nothing useful to document about these
@@ -26,6 +51,7 @@ impl Revision {
26
51
pub const EFI_2_70 : Self = Self :: new ( 2 , 70 ) ;
27
52
pub const EFI_2_80 : Self = Self :: new ( 2 , 80 ) ;
28
53
pub const EFI_2_90 : Self = Self :: new ( 2 , 90 ) ;
54
+ pub const EFI_2_100 : Self = Self :: new ( 2 , 100 ) ;
29
55
}
30
56
31
57
impl Revision {
@@ -48,13 +74,20 @@ impl Revision {
48
74
}
49
75
}
50
76
51
- impl fmt:: Debug for Revision {
52
- /// Formats the revision in the `major.minor.patch` format.
77
+ impl fmt:: Display for Revision {
53
78
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
54
79
let ( major, minor) = ( self . major ( ) , self . minor ( ) ) ;
55
- let minor = minor / 10 ;
56
- let patch = minor % 10 ;
57
- write ! ( f, "{major}.{minor}.{patch}" )
80
+
81
+ if major < 2 {
82
+ write ! ( f, "{major}.{minor:02}" )
83
+ } else {
84
+ let ( minor, patch) = ( minor / 10 , minor % 10 ) ;
85
+ if patch == 0 {
86
+ write ! ( f, "{major}.{minor}" )
87
+ } else {
88
+ write ! ( f, "{major}.{minor}.{patch}" )
89
+ }
90
+ }
58
91
}
59
92
}
60
93
0 commit comments