@@ -9,21 +9,41 @@ use core::fmt;
9
9
#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd ) ]
10
10
pub struct Revision ( u32 ) ;
11
11
12
+ // Allow missing docs, there's nothing useful to document about these
13
+ // constants.
14
+ #[ allow( missing_docs) ]
15
+ impl Revision {
16
+ pub const EFI_1_02 : Self = Self :: new ( 1 , 2 ) ;
17
+ pub const EFI_1_10 : Self = Self :: new ( 1 , 10 ) ;
18
+ pub const EFI_2_00 : Self = Self :: new ( 2 , 00 ) ;
19
+ pub const EFI_2_10 : Self = Self :: new ( 2 , 10 ) ;
20
+ pub const EFI_2_20 : Self = Self :: new ( 2 , 20 ) ;
21
+ pub const EFI_2_30 : Self = Self :: new ( 2 , 30 ) ;
22
+ pub const EFI_2_31 : Self = Self :: new ( 2 , 31 ) ;
23
+ pub const EFI_2_40 : Self = Self :: new ( 2 , 40 ) ;
24
+ pub const EFI_2_50 : Self = Self :: new ( 2 , 50 ) ;
25
+ pub const EFI_2_60 : Self = Self :: new ( 2 , 60 ) ;
26
+ pub const EFI_2_70 : Self = Self :: new ( 2 , 70 ) ;
27
+ pub const EFI_2_80 : Self = Self :: new ( 2 , 80 ) ;
28
+ pub const EFI_2_90 : Self = Self :: new ( 2 , 90 ) ;
29
+ }
30
+
12
31
impl Revision {
13
32
/// Creates a new revision.
14
- pub fn new ( major : u16 , minor : u16 ) -> Self {
15
- let ( major, minor) = ( u32:: from ( major) , u32:: from ( minor) ) ;
33
+ pub const fn new ( major : u16 , minor : u16 ) -> Self {
34
+ let major = major as u32 ;
35
+ let minor = minor as u32 ;
16
36
let value = ( major << 16 ) | minor;
17
37
Revision ( value)
18
38
}
19
39
20
40
/// Returns the major revision.
21
- pub fn major ( self ) -> u16 {
41
+ pub const fn major ( self ) -> u16 {
22
42
( self . 0 >> 16 ) as u16
23
43
}
24
44
25
45
/// Returns the minor revision.
26
- pub fn minor ( self ) -> u16 {
46
+ pub const fn minor ( self ) -> u16 {
27
47
self . 0 as u16
28
48
}
29
49
}
@@ -35,3 +55,18 @@ impl fmt::Debug for Revision {
35
55
write ! ( f, "{}.{}.{}" , major, minor / 10 , minor % 10 )
36
56
}
37
57
}
58
+
59
+ #[ cfg( test) ]
60
+ mod tests {
61
+ use super :: * ;
62
+
63
+ #[ test]
64
+ fn test_revision ( ) {
65
+ let rev = Revision :: EFI_2_31 ;
66
+ assert_eq ! ( rev. major( ) , 2 ) ;
67
+ assert_eq ! ( rev. minor( ) , 31 ) ;
68
+ assert_eq ! ( rev. 0 , 0x0002_001f ) ;
69
+
70
+ assert ! ( Revision :: EFI_1_10 < Revision :: EFI_2_00 ) ;
71
+ }
72
+ }
0 commit comments