rust/crates/core_simd/src/fmt.rs
Jubilee ceb2611592
Remove formats [T; N] does not impl (rust-lang/portable-simd#337)
Remove these extra formatting traits, as they are
inconsistent with how arrays and slices format,
and it can cause unnecessary code bloat in binaries.
We can revisit this if people ever agree on doing these
formatters for the other slice-y types.

Prefer to dispatch to the `impl `fmt::Debug for [T]`,
to reduce the chances of monomorphizing twice.
Inlining it seems like a good idea for similar reasons?
2023-04-09 21:26:40 -07:00

22 lines
746 B
Rust

use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
use core::fmt;
impl<T, const LANES: usize> fmt::Debug for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
T: SimdElement + fmt::Debug,
{
/// A `Simd<T, N>` has a debug format like the one for `[T]`:
/// ```
/// # #![feature(portable_simd)]
/// # #[cfg(feature = "as_crate")] use core_simd::simd::Simd;
/// # #[cfg(not(feature = "as_crate"))] use core::simd::Simd;
/// let floats = Simd::<f32, 4>::splat(-1.0);
/// assert_eq!(format!("{:?}", [-1.0; 4]), format!("{:?}", floats));
/// ```
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<[T] as fmt::Debug>::fmt(self.as_array(), f)
}
}