Skip to content

Commit c949c3d

Browse files
alexcrichtonBurntSushi
authored andcommitted
Add fmt::LowerHex to integer simd for debugging
Helped me locally at least! Curious what you think.
1 parent c9cc091 commit c949c3d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/macros.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ macro_rules! define_integer_ops {
227227
$ty, $elem,
228228
u8, u16, u32, u64, usize,
229229
i8, i16, i32, i64, isize);
230+
231+
impl ::std::fmt::LowerHex for $ty {
232+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
233+
write!(f, "{}(", stringify!($ty))?;
234+
let n = ::std::mem::size_of_val(self) / ::std::mem::size_of::<$elem>();
235+
for i in 0..n {
236+
if i > 0 {
237+
write!(f, ", ")?;
238+
}
239+
write!(f, "{:#x}", self.extract(i as u32))?;
240+
}
241+
write!(f, ")")
242+
}
243+
}
230244
)+
231245
}
232246
}

0 commit comments

Comments
 (0)