Skip to content

Commit b644c2c

Browse files
committed
Format addresses as hexadecimal for VirtAddr/PhysAddr error types
1 parent b40eac1 commit b644c2c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/addr.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ pub struct PhysAddr(u64);
4040
/// a valid sign extension and are not null either. So automatic sign extension would have
4141
/// overwritten possibly meaningful bits. This likely indicates a bug, for example an invalid
4242
/// address calculation.
43-
#[derive(Debug)]
43+
///
44+
/// Contains the invalid address.
4445
pub struct VirtAddrNotValid(pub u64);
4546

47+
impl core::fmt::Debug for VirtAddrNotValid {
48+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49+
f.debug_tuple("VirtAddrNotValid")
50+
.field(&format_args!("{:#x}", self.0))
51+
.finish()
52+
}
53+
}
54+
4655
impl VirtAddr {
4756
/// Creates a new canonical virtual address.
4857
///
@@ -325,9 +334,18 @@ impl Sub<VirtAddr> for VirtAddr {
325334
/// A passed `u64` was not a valid physical address.
326335
///
327336
/// This means that bits 52 to 64 were not all null.
328-
#[derive(Debug)]
337+
///
338+
/// Contains the invalid address.
329339
pub struct PhysAddrNotValid(pub u64);
330340

341+
impl core::fmt::Debug for PhysAddrNotValid {
342+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
343+
f.debug_tuple("PhysAddrNotValid")
344+
.field(&format_args!("{:#x}", self.0))
345+
.finish()
346+
}
347+
}
348+
331349
impl PhysAddr {
332350
/// Creates a new physical address.
333351
///

0 commit comments

Comments
 (0)