|
| 1 | +macro_rules! debug_wrapper { |
| 2 | + { $($trait:ident => $name:ident,)* } => { |
| 3 | + $( |
| 4 | + pub(crate) fn $name<T: core::fmt::$trait>(slice: &[T], f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 5 | + #[repr(transparent)] |
| 6 | + struct Wrapper<'a, T: core::fmt::$trait>(&'a T); |
| 7 | + |
| 8 | + impl<T: core::fmt::$trait> core::fmt::Debug for Wrapper<'_, T> { |
| 9 | + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 10 | + self.0.fmt(f) |
| 11 | + } |
| 12 | + } |
| 13 | + |
| 14 | + f.debug_list() |
| 15 | + .entries(slice.iter().map(|x| Wrapper(x))) |
| 16 | + .finish() |
| 17 | + } |
| 18 | + )* |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +debug_wrapper! { |
| 23 | + Debug => format, |
| 24 | + Binary => format_binary, |
| 25 | + LowerExp => format_lower_exp, |
| 26 | + UpperExp => format_upper_exp, |
| 27 | + Octal => format_octal, |
| 28 | + LowerHex => format_lower_hex, |
| 29 | + UpperHex => format_upper_hex, |
| 30 | +} |
| 31 | + |
| 32 | +macro_rules! impl_fmt_trait { |
| 33 | + { $($type:ty => $(($trait:ident, $format:ident)),*;)* } => { |
| 34 | + $( // repeat type |
| 35 | + $( // repeat trait |
| 36 | + impl core::fmt::$trait for $type { |
| 37 | + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 38 | + $format(self.as_ref(), f) |
| 39 | + } |
| 40 | + } |
| 41 | + )* |
| 42 | + )* |
| 43 | + }; |
| 44 | + { integers: $($type:ty,)* } => { |
| 45 | + impl_fmt_trait! { |
| 46 | + $($type => |
| 47 | + (Debug, format), |
| 48 | + (Binary, format_binary), |
| 49 | + (LowerExp, format_lower_exp), |
| 50 | + (UpperExp, format_upper_exp), |
| 51 | + (Octal, format_octal), |
| 52 | + (LowerHex, format_lower_hex), |
| 53 | + (UpperHex, format_upper_hex); |
| 54 | + )* |
| 55 | + } |
| 56 | + }; |
| 57 | + { floats: $($type:ty,)* } => { |
| 58 | + impl_fmt_trait! { |
| 59 | + $($type => |
| 60 | + (Debug, format), |
| 61 | + (LowerExp, format_lower_exp), |
| 62 | + (UpperExp, format_upper_exp); |
| 63 | + )* |
| 64 | + } |
| 65 | + }; |
| 66 | + { masks: $($type:ty,)* } => { |
| 67 | + impl_fmt_trait! { |
| 68 | + $($type => |
| 69 | + (Debug, format); |
| 70 | + )* |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +impl_fmt_trait! { |
| 76 | + integers: |
| 77 | + crate::u8x8, crate::u8x16, crate::u8x32, crate::u8x64, |
| 78 | + crate::i8x8, crate::i8x16, crate::i8x32, crate::i8x64, |
| 79 | + crate::u16x4, crate::u16x8, crate::u16x16, crate::u16x32, |
| 80 | + crate::i16x4, crate::i16x8, crate::i16x16, crate::i16x32, |
| 81 | + crate::u32x2, crate::u32x4, crate::u32x8, crate::u32x16, |
| 82 | + crate::i32x2, crate::i32x4, crate::i32x8, crate::i32x16, |
| 83 | + crate::u64x2, crate::u64x4, crate::u64x8, |
| 84 | + crate::i64x2, crate::i64x4, crate::i64x8, |
| 85 | + crate::u128x2, crate::u128x4, |
| 86 | + crate::i128x2, crate::i128x4, |
| 87 | + crate::usizex2, crate::usizex4, crate::usizex8, |
| 88 | + crate::isizex2, crate::isizex4, crate::isizex8, |
| 89 | +} |
| 90 | + |
| 91 | +impl_fmt_trait! { |
| 92 | + floats: |
| 93 | + crate::f32x2, crate::f32x4, crate::f32x8, crate::f32x16, |
| 94 | + crate::f64x2, crate::f64x4, crate::f64x8, |
| 95 | +} |
| 96 | + |
| 97 | +impl_fmt_trait! { |
| 98 | + masks: |
| 99 | + crate::mask8x8, crate::mask8x16, crate::mask8x32, crate::mask8x64, |
| 100 | + crate::mask16x4, crate::mask16x8, crate::mask16x16, crate::mask16x32, |
| 101 | + crate::mask32x2, crate::mask32x4, crate::mask32x8, crate::mask32x16, |
| 102 | + crate::mask64x2, crate::mask64x4, crate::mask64x8, |
| 103 | + crate::mask128x2, crate::mask128x4, |
| 104 | + crate::masksizex2, crate::masksizex4, crate::masksizex8, |
| 105 | +} |
0 commit comments