Skip to content

Commit

Permalink
fix: implement Debug like Display
Browse files Browse the repository at this point in the history
If PhantomData<U> does not implement Debug, the Offset<T, U> does not
implement Debug, although T might implement Debug.

Signed-off-by: Harald Hoyer <harald@profian.com>
  • Loading branch information
haraldh authored and npmccallum committed Mar 30, 2022
1 parent b606b9e commit 3511d51
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ use core::ops::*;
/// underlying types so long as the conversion is lossless for the target CPU
/// architecture. For example, `Offset<u64>` can be converted to
/// `Offset<usize>` on 64-bit systems.
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Default)]
#[repr(transparent)]
pub struct Offset<T, U>(T, PhantomData<U>);

impl<T: core::fmt::Debug, U> core::fmt::Debug for Offset<T, U> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(&self.0, f)
}
}

impl<T: core::fmt::Binary, U> core::fmt::Binary for Offset<T, U> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Binary::fmt(&self.0, f)
Expand Down

0 comments on commit 3511d51

Please sign in to comment.