]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/fmt.rs
Auto merge of #89167 - workingjubilee:use-simd, r=MarkSimulacrum
[rust.git] / library / portable-simd / crates / core_simd / src / fmt.rs
1 use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
2 use core::fmt;
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         )*
28     }
29 }
30
31 impl_fmt_trait! {
32     Debug,
33     Binary,
34     LowerExp,
35     UpperExp,
36     Octal,
37     LowerHex,
38     UpperHex,
39 }