rust/crates/core_simd/src/fmt.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
use core::fmt;
2021-08-05 22:45:57 -05:00
macro_rules! impl_fmt_trait {
{ $($trait:ident,)* } => {
$(
impl<T, const LANES: usize> fmt::$trait for Simd<T, LANES>
2021-08-05 22:45:57 -05:00
where
LaneCount<LANES>: SupportedLaneCount,
T: SimdElement + fmt::$trait,
2021-08-05 22:45:57 -05:00
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2021-08-05 22:45:57 -05:00
#[repr(transparent)]
struct Wrapper<'a, T: fmt::$trait>(&'a T);
impl<T: fmt::$trait> fmt::Debug for Wrapper<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2021-08-05 22:45:57 -05:00
self.0.fmt(f)
}
}
2021-08-05 22:45:57 -05:00
f.debug_list()
.entries(self.as_array().iter().map(|x| Wrapper(x)))
.finish()
}
2021-08-05 22:45:57 -05:00
}
)*
}
}
impl_fmt_trait! {
2021-08-05 22:45:57 -05:00
Debug,
Binary,
LowerExp,
UpperExp,
Octal,
LowerHex,
UpperHex,
}