1 | use crate::simd::SimdElement; |
2 | |
3 | mod sealed { |
4 | /// Cast vector elements to other types. |
5 | /// |
6 | /// # Safety |
7 | /// Implementing this trait asserts that the type is a valid vector element for the `simd_cast` |
8 | /// or `simd_as` intrinsics. |
9 | pub unsafe trait Sealed {} |
10 | } |
11 | use sealed::Sealed; |
12 | |
13 | /// Supporting trait for `Simd::cast`. Typically doesn't need to be used directly. |
14 | pub trait SimdCast: Sealed + SimdElement {} |
15 | |
16 | // Safety: primitive number types can be cast to other primitive number types |
17 | unsafe impl Sealed for i8 {} |
18 | impl SimdCast for i8 {} |
19 | // Safety: primitive number types can be cast to other primitive number types |
20 | unsafe impl Sealed for i16 {} |
21 | impl SimdCast for i16 {} |
22 | // Safety: primitive number types can be cast to other primitive number types |
23 | unsafe impl Sealed for i32 {} |
24 | impl SimdCast for i32 {} |
25 | // Safety: primitive number types can be cast to other primitive number types |
26 | unsafe impl Sealed for i64 {} |
27 | impl SimdCast for i64 {} |
28 | // Safety: primitive number types can be cast to other primitive number types |
29 | unsafe impl Sealed for isize {} |
30 | impl SimdCast for isize {} |
31 | // Safety: primitive number types can be cast to other primitive number types |
32 | unsafe impl Sealed for u8 {} |
33 | impl SimdCast for u8 {} |
34 | // Safety: primitive number types can be cast to other primitive number types |
35 | unsafe impl Sealed for u16 {} |
36 | impl SimdCast for u16 {} |
37 | // Safety: primitive number types can be cast to other primitive number types |
38 | unsafe impl Sealed for u32 {} |
39 | impl SimdCast for u32 {} |
40 | // Safety: primitive number types can be cast to other primitive number types |
41 | unsafe impl Sealed for u64 {} |
42 | impl SimdCast for u64 {} |
43 | // Safety: primitive number types can be cast to other primitive number types |
44 | unsafe impl Sealed for usize {} |
45 | impl SimdCast for usize {} |
46 | // Safety: primitive number types can be cast to other primitive number types |
47 | unsafe impl Sealed for f32 {} |
48 | impl SimdCast for f32 {} |
49 | // Safety: primitive number types can be cast to other primitive number types |
50 | unsafe impl Sealed for f64 {} |
51 | impl SimdCast for f64 {} |
52 | |