mirror of
https://github.com/rust-osdev/uefi-rs
synced 2026-08-26 18:26:05 -04:00
uefi-raw: add helpers to Boolean type for logical equality
This commit is contained in:
parent
4f8ca7069c
commit
80079fbc92
2 changed files with 26 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue