|
1 | 1 | use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; |
2 | 2 | use core::fmt; |
3 | 3 |
|
4 | | -macro_rules! impl_fmt_trait { |
5 | | - { $($trait:ident,)* } => { |
6 | | - $( |
7 | | - impl<T, const LANES: usize> fmt::$trait for Simd<T, LANES> |
8 | | - where |
9 | | - LaneCount<LANES>: SupportedLaneCount, |
10 | | - T: SimdElement + fmt::$trait, |
11 | | - { |
12 | | - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
13 | | - #[repr(transparent)] |
14 | | - struct Wrapper<'a, T: fmt::$trait>(&'a T); |
15 | | - |
16 | | - impl<T: fmt::$trait> fmt::Debug for Wrapper<'_, T> { |
17 | | - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
18 | | - self.0.fmt(f) |
19 | | - } |
20 | | - } |
21 | | - |
22 | | - f.debug_list() |
23 | | - .entries(self.as_array().iter().map(|x| Wrapper(x))) |
24 | | - .finish() |
25 | | - } |
26 | | - } |
27 | | - )* |
| 4 | +impl<T, const LANES: usize> fmt::Debug for Simd<T, LANES> |
| 5 | +where |
| 6 | + LaneCount<LANES>: SupportedLaneCount, |
| 7 | + T: SimdElement + fmt::Debug, |
| 8 | +{ |
| 9 | + /// A `Simd<T, N>` has a debug format like the one for `[T]`: |
| 10 | + /// ``` |
| 11 | + /// # #![feature(portable_simd)] |
| 12 | + /// # #[cfg(feature = "as_crate")] use core_simd::simd::Simd; |
| 13 | + /// # #[cfg(not(feature = "as_crate"))] use core::simd::Simd; |
| 14 | + /// let floats = Simd::<f32, 4>::splat(-1.0); |
| 15 | + /// assert_eq!(format!("{:?}", [-1.0; 4]), format!("{:?}", floats)); |
| 16 | + /// ``` |
| 17 | + #[inline] |
| 18 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 19 | + <[T] as fmt::Debug>::fmt(self.as_array(), f) |
28 | 20 | } |
29 | 21 | } |
30 | | - |
31 | | -impl_fmt_trait! { |
32 | | - Debug, |
33 | | - Binary, |
34 | | - LowerExp, |
35 | | - UpperExp, |
36 | | - Octal, |
37 | | - LowerHex, |
38 | | - UpperHex, |
39 | | -} |
0 commit comments