uefi-raw: add helpers to Boolean type for logical equality

This commit is contained in:
Philipp Schuster 2026-08-24 20:34:34 +02:00
parent 4f8ca7069c
commit 80079fbc92
No known key found for this signature in database
2 changed files with 26 additions and 7 deletions

View file

@ -3,6 +3,8 @@
## Added
- Added the revision constants `BlockIoProtocol::{REVISION, REVISION_2,
REVISION_3}`.
- Added `Boolean::is_true()` and `Boolean::is_false()` for a quick conversion
of an EFI boolean to a Rust boolean.
## Changed
- **Breaking**: `MemoryDescriptor` now has a new member to ensure correct

View file

@ -105,6 +105,29 @@ impl Boolean {
/// [`Boolean`] representing `false`.
pub const FALSE: Self = Self(0);
/// Const-compatible check for **logical equality**.
const fn eq_const(self, other: Self) -> bool {
match (self.0, other.0) {
(0, 0) => true,
(0, _) => false,
(_, 0) => false,
// We handle it as in C: Any bit-pattern != 0 equals true
(_, _) => true,
}
}
/// Returns whether the underlying value equals a Rust `true`.
#[must_use]
pub const fn is_true(self) -> bool {
Self::eq_const(self, Self::TRUE)
}
/// Returns whether the underlying value equals a Rust `true`.
#[must_use]
pub const fn is_false(self) -> bool {
!self.is_true()
}
}
impl From<u8> for Boolean {
@ -135,13 +158,7 @@ impl From<Boolean> for bool {
impl PartialEq for Boolean {
fn eq(&self, other: &Self) -> bool {
match (self.0, other.0) {
(0, 0) => true,
(0, _) => false,
(_, 0) => false,
// We handle it as in C: Any bit-pattern != 0 equals true
(_, _) => true,
}
Self::eq_const(*self, *other)
}
}