Skip to content

Commit 05a8211

Browse files
Implement PartialEq<char> for Char8 and Char16
1 parent 9797333 commit 05a8211

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

uefi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# uefi - [Unreleased]
22

3+
## Added
4+
- Implemented `PartialEq<char>` for `Char8` and `Char16`.
5+
36
# uefi - 0.26.0 (2023-11-12)
47

58
## Added

uefi/src/data_types/chars.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ impl fmt::Display for Char8 {
6666
}
6767
}
6868

69+
impl PartialEq<char> for Char8 {
70+
fn eq(&self, other: &char) -> bool {
71+
u32::from(self.0) == u32::from(*other)
72+
}
73+
}
74+
6975
/// Latin-1 version of the NUL character
7076
pub const NUL_8: Char8 = Char8(0);
7177

@@ -150,5 +156,24 @@ impl fmt::Display for Char16 {
150156
}
151157
}
152158

159+
impl PartialEq<char> for Char16 {
160+
fn eq(&self, other: &char) -> bool {
161+
u32::from(self.0) == u32::from(*other)
162+
}
163+
}
164+
153165
/// UCS-2 version of the NUL character
154166
pub const NUL_16: Char16 = unsafe { Char16::from_u16_unchecked(0) };
167+
168+
#[cfg(test)]
169+
mod tests {
170+
use super::*;
171+
172+
/// Test that `Char8` and `Char16` can be directly compared with `char`.
173+
#[test]
174+
fn test_char_eq() {
175+
let primitive_char: char = 'A';
176+
assert_eq!(Char8(0x41), primitive_char);
177+
assert_eq!(Char16(0x41), primitive_char);
178+
}
179+
}

0 commit comments

Comments
 (0)