@@ -6,7 +6,31 @@ 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 ) ]
10
34
#[ repr( transparent) ]
11
35
pub struct Revision ( u32 ) ;
12
36
@@ -50,13 +74,20 @@ impl Revision {
50
74
}
51
75
}
52
76
53
- impl fmt:: Debug for Revision {
54
- /// Formats the revision in the `major.minor.patch` format.
77
+ impl fmt:: Display for Revision {
55
78
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
56
79
let ( major, minor) = ( self . major ( ) , self . minor ( ) ) ;
57
- let minor = minor / 10 ;
58
- let patch = minor % 10 ;
59
- 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
+ }
60
91
}
61
92
}
62
93
0 commit comments