Skip to content

Commit b84fa5f

Browse files
Add Revision constants and constify Revision methods
Add constants for all the EFI versions (from section 4.3 "EFI System Table"). Also make the new/major/minor methods of Revision const.
1 parent 190bf5b commit b84fa5f

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## uefi - [Unreleased]
44

5+
### Added
6+
7+
- Added EFI revision constants to `Revision`.
8+
59
## uefi-macros - [Unreleased]
610

711
## uefi-services - [Unreleased]
@@ -32,6 +36,7 @@
3236
- `DevicePath` is now a DST that represents an entire device path. The
3337
`DevicePathInstance` and `DevicePathNode` provide views of path
3438
instances and nodes, respectively.
39+
- The methods of `Revision` are now `const`.
3540

3641
### Fixed
3742

src/table/revision.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,41 @@ use core::fmt;
99
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
1010
pub struct Revision(u32);
1111

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+
1231
impl Revision {
1332
/// 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;
1636
let value = (major << 16) | minor;
1737
Revision(value)
1838
}
1939

2040
/// Returns the major revision.
21-
pub fn major(self) -> u16 {
41+
pub const fn major(self) -> u16 {
2242
(self.0 >> 16) as u16
2343
}
2444

2545
/// Returns the minor revision.
26-
pub fn minor(self) -> u16 {
46+
pub const fn minor(self) -> u16 {
2747
self.0 as u16
2848
}
2949
}
@@ -35,3 +55,18 @@ impl fmt::Debug for Revision {
3555
write!(f, "{}.{}.{}", major, minor / 10, minor % 10)
3656
}
3757
}
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

Comments
 (0)