1 //! Implement `LowerHex` formatting
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
{
7 feature
= "cargo-clippy", allow(clippy
::missing_inline_in_public_items
)
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
{
16 self.extract(i
).fmt(f
)?
;
24 pub mod [<$id _fmt_lower_hex
>] {
26 #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
28 use arrayvec
::{ArrayString,ArrayVec}
;
29 type TinyString
= ArrayString
<[u8; 512]>;
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();
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(")", "")
43 .map(|v
| TinyString
::from(v
.trim()).unwrap())
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();