Skip to content

Commit 7c2b26d

Browse files
authored
Merge pull request #237 from dbeckwith/dbeckwith.fmt-impls
Implement more fmt traits for addr types
2 parents 1fd6937 + 7e48944 commit 7c2b26d

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

src/addr.rs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,44 @@ impl VirtAddr {
202202

203203
impl fmt::Debug for VirtAddr {
204204
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
205-
write!(f, "VirtAddr({:#x})", self.0)
205+
f.debug_tuple("VirtAddr")
206+
.field(&format_args!("{:#x}", self.0))
207+
.finish()
208+
}
209+
}
210+
211+
impl fmt::Binary for VirtAddr {
212+
#[inline]
213+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
214+
fmt::Binary::fmt(&self.0, f)
215+
}
216+
}
217+
218+
impl fmt::LowerHex for VirtAddr {
219+
#[inline]
220+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
221+
fmt::LowerHex::fmt(&self.0, f)
222+
}
223+
}
224+
225+
impl fmt::Octal for VirtAddr {
226+
#[inline]
227+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
228+
fmt::Octal::fmt(&self.0, f)
229+
}
230+
}
231+
232+
impl fmt::UpperHex for VirtAddr {
233+
#[inline]
234+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
235+
fmt::UpperHex::fmt(&self.0, f)
236+
}
237+
}
238+
239+
impl fmt::Pointer for VirtAddr {
240+
#[inline]
241+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
242+
fmt::Pointer::fmt(&(self.0 as *const ()), f)
206243
}
207244
}
208245

@@ -379,35 +416,44 @@ impl PhysAddr {
379416

380417
impl fmt::Debug for PhysAddr {
381418
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
382-
write!(f, "PhysAddr({:#x})", self.0)
419+
f.debug_tuple("PhysAddr")
420+
.field(&format_args!("{:#x}", self.0))
421+
.finish()
383422
}
384423
}
385424

386425
impl fmt::Binary for PhysAddr {
387426
#[inline]
388427
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
389-
self.0.fmt(f)
428+
fmt::Binary::fmt(&self.0, f)
390429
}
391430
}
392431

393432
impl fmt::LowerHex for PhysAddr {
394433
#[inline]
395434
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
396-
self.0.fmt(f)
435+
fmt::LowerHex::fmt(&self.0, f)
397436
}
398437
}
399438

400439
impl fmt::Octal for PhysAddr {
401440
#[inline]
402441
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
403-
self.0.fmt(f)
442+
fmt::Octal::fmt(&self.0, f)
404443
}
405444
}
406445

407446
impl fmt::UpperHex for PhysAddr {
408447
#[inline]
409448
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
410-
self.0.fmt(f)
449+
fmt::UpperHex::fmt(&self.0, f)
450+
}
451+
}
452+
453+
impl fmt::Pointer for PhysAddr {
454+
#[inline]
455+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
456+
fmt::Pointer::fmt(&(self.0 as *const ()), f)
411457
}
412458
}
413459

0 commit comments

Comments
 (0)