]> git.proxmox.com Git - rustc.git/blob - vendor/packed_simd/src/api/fmt/lower_hex.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / vendor / packed_simd / src / api / fmt / lower_hex.rs
1 //! Implement `LowerHex` formatting
2
3 macro_rules! impl_fmt_lower_hex {
4 ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => {
5 impl crate::fmt::LowerHex for $id {
6 #[cfg_attr(
7 feature = "cargo-clippy", allow(clippy::missing_inline_in_public_items)
8 )]
9 fn fmt(&self, f: &mut crate::fmt::Formatter<'_>)
10 -> crate::fmt::Result {
11 write!(f, "{}(", stringify!($id))?;
12 for i in 0..$elem_count {
13 if i > 0 {
14 write!(f, ", ")?;
15 }
16 self.extract(i).fmt(f)?;
17 }
18 write!(f, ")")
19 }
20 }
21 test_if!{
22 $test_tt:
23 paste::item! {
24 pub mod [<$id _fmt_lower_hex>] {
25 use super::*;
26 #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
27 fn lower_hex() {
28 use arrayvec::{ArrayString,ArrayVec};
29 type TinyString = ArrayString<[u8; 512]>;
30
31 use crate::fmt::Write;
32 let v = $id::splat($elem_ty::default());
33 let mut s = TinyString::new();
34 write!(&mut s, "{:#x}", v).unwrap();
35
36 let mut beg = TinyString::new();
37 write!(&mut beg, "{}(", stringify!($id)).unwrap();
38 assert!(s.starts_with(beg.as_str()));
39 assert!(s.ends_with(")"));
40 let s: ArrayVec<[TinyString; 64]>
41 = s.replace(beg.as_str(), "").replace(")", "")
42 .split(",")
43 .map(|v| TinyString::from(v.trim()).unwrap())
44 .collect();
45 assert_eq!(s.len(), $id::lanes());
46 for (index, ss) in s.into_iter().enumerate() {
47 let mut e = TinyString::new();
48 write!(&mut e, "{:#x}", v.extract(index)).unwrap();
49 assert_eq!(ss, e);
50 }
51 }
52 }
53 }
54 }
55 };
56 }