|
1 |
| -macro_rules! debug_wrapper { |
2 |
| - { $($trait:ident => $name:ident,)* } => { |
| 1 | +macro_rules! impl_fmt_trait { |
| 2 | + { $($trait:ident,)* } => { |
3 | 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); |
| 4 | + impl<Element, const LANES: usize> core::fmt::$trait for crate::Simd<Element, LANES> |
| 5 | + where |
| 6 | + crate::LaneCount<LANES>: crate::SupportedLaneCount, |
| 7 | + Element: crate::SimdElement + core::fmt::$trait, |
| 8 | + { |
| 9 | + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 10 | + #[repr(transparent)] |
| 11 | + struct Wrapper<'a, T: core::fmt::$trait>(&'a T); |
7 | 12 |
|
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) |
| 13 | + impl<T: core::fmt::$trait> core::fmt::Debug for Wrapper<'_, T> { |
| 14 | + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 15 | + self.0.fmt(f) |
| 16 | + } |
11 | 17 | }
|
12 |
| - } |
13 |
| - |
14 |
| - f.debug_list() |
15 |
| - .entries(slice.iter().map(|x| Wrapper(x))) |
16 |
| - .finish() |
17 |
| - } |
18 |
| - )* |
19 |
| - } |
20 |
| -} |
21 | 18 |
|
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:ident => $(($trait:ident, $format:ident)),*;)* } => { |
34 |
| - $( // repeat type |
35 |
| - $( // repeat trait |
36 |
| - impl<const LANES: usize> core::fmt::$trait for crate::$type<LANES> |
37 |
| - where |
38 |
| - crate::LaneCount<LANES>: crate::SupportedLaneCount, |
39 |
| - { |
40 |
| - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
41 |
| - $format(self.as_ref(), f) |
42 |
| - } |
| 19 | + f.debug_list() |
| 20 | + .entries(self.as_array().iter().map(|x| Wrapper(x))) |
| 21 | + .finish() |
43 | 22 | }
|
44 |
| - )* |
| 23 | + } |
45 | 24 | )*
|
46 |
| - }; |
47 |
| - { integers: $($type:ident,)* } => { |
48 |
| - impl_fmt_trait! { |
49 |
| - $($type => |
50 |
| - (Debug, format), |
51 |
| - (Binary, format_binary), |
52 |
| - (LowerExp, format_lower_exp), |
53 |
| - (UpperExp, format_upper_exp), |
54 |
| - (Octal, format_octal), |
55 |
| - (LowerHex, format_lower_hex), |
56 |
| - (UpperHex, format_upper_hex); |
57 |
| - )* |
58 |
| - } |
59 |
| - }; |
60 |
| - { floats: $($type:ident,)* } => { |
61 |
| - impl_fmt_trait! { |
62 |
| - $($type => |
63 |
| - (Debug, format), |
64 |
| - (LowerExp, format_lower_exp), |
65 |
| - (UpperExp, format_upper_exp); |
66 |
| - )* |
67 |
| - } |
68 |
| - }; |
69 |
| - { masks: $($type:ident,)* } => { |
70 |
| - impl_fmt_trait! { |
71 |
| - $($type => |
72 |
| - (Debug, format); |
73 |
| - )* |
74 |
| - } |
75 | 25 | }
|
76 | 26 | }
|
77 | 27 |
|
78 | 28 | impl_fmt_trait! {
|
79 |
| - integers: |
80 |
| - SimdU8, SimdU16, SimdU32, SimdU64, |
81 |
| - SimdI8, SimdI16, SimdI32, SimdI64, |
82 |
| - SimdUsize, SimdIsize, |
83 |
| -} |
84 |
| - |
85 |
| -impl_fmt_trait! { |
86 |
| - floats: |
87 |
| - SimdF32, SimdF64, |
| 29 | + Debug, |
| 30 | + Binary, |
| 31 | + LowerExp, |
| 32 | + UpperExp, |
| 33 | + Octal, |
| 34 | + LowerHex, |
| 35 | + UpperHex, |
88 | 36 | }
|
0 commit comments