Skip to content

Commit c6de9f6

Browse files
committed
Implement PartialEq, Eq, and Debug for Entry
Signed-off-by: Joe Richey <[email protected]>
1 parent 48dbe8f commit c6de9f6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/structures/gdt.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::structures::tss::TaskStateSegment;
55
use crate::PrivilegeLevel;
66
use bit_field::BitField;
77
use bitflags::bitflags;
8+
use core::fmt;
89
// imports for intra-doc links
910
#[cfg(doc)]
1011
use crate::registers::segmentation::{Segment, CS, SS};
@@ -16,7 +17,7 @@ use crate::registers::segmentation::{Segment, CS, SS};
1617
/// uses either 1 Entry (if it is a [`UserSegment`](Descriptor::UserSegment)) or
1718
/// 2 Entries (if it is a [`SystemSegment`](Descriptor::SystemSegment)). This
1819
/// type exists to give users access to the raw entry bits in a GDT.
19-
#[derive(Clone, Debug)]
20+
#[derive(Clone)]
2021
#[repr(transparent)]
2122
pub struct Entry(u64);
2223

@@ -33,6 +34,20 @@ impl Entry {
3334
}
3435
}
3536

37+
impl PartialEq for Entry {
38+
fn eq(&self, other: &Self) -> bool {
39+
self.raw() == other.raw()
40+
}
41+
}
42+
impl Eq for Entry {}
43+
44+
impl fmt::Debug for Entry {
45+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46+
// Display inner value as hex
47+
write!(f, "Entry({:#018x})", self.raw())
48+
}
49+
}
50+
3651
/// A 64-bit mode global descriptor table (GDT).
3752
///
3853
/// In 64-bit mode, segmentation is not supported. The GDT is used nonetheless, for example for

0 commit comments

Comments
 (0)