|
1 | 1 | use crate::simd::SimdElement;
|
2 | 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 | + |
3 | 13 | /// Supporting trait for `Simd::cast`. Typically doesn't need to be used directly.
|
4 |
| -/// |
5 |
| -/// # Safety |
6 |
| -/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast` or |
7 |
| -/// `simd_as` intrinsics. |
8 |
| -pub unsafe trait SimdCast: SimdElement {} |
| 14 | +pub trait SimdCast: Sealed + SimdElement {} |
9 | 15 |
|
10 | 16 | // Safety: primitive number types can be cast to other primitive number types
|
11 |
| -unsafe impl SimdCast for i8 {} |
| 17 | +unsafe impl Sealed for i8 {} |
| 18 | +impl SimdCast for i8 {} |
12 | 19 | // Safety: primitive number types can be cast to other primitive number types
|
13 |
| -unsafe impl SimdCast for i16 {} |
| 20 | +unsafe impl Sealed for i16 {} |
| 21 | +impl SimdCast for i16 {} |
14 | 22 | // Safety: primitive number types can be cast to other primitive number types
|
15 |
| -unsafe impl SimdCast for i32 {} |
| 23 | +unsafe impl Sealed for i32 {} |
| 24 | +impl SimdCast for i32 {} |
16 | 25 | // Safety: primitive number types can be cast to other primitive number types
|
17 |
| -unsafe impl SimdCast for i64 {} |
| 26 | +unsafe impl Sealed for i64 {} |
| 27 | +impl SimdCast for i64 {} |
18 | 28 | // Safety: primitive number types can be cast to other primitive number types
|
19 |
| -unsafe impl SimdCast for isize {} |
| 29 | +unsafe impl Sealed for isize {} |
| 30 | +impl SimdCast for isize {} |
20 | 31 | // Safety: primitive number types can be cast to other primitive number types
|
21 |
| -unsafe impl SimdCast for u8 {} |
| 32 | +unsafe impl Sealed for u8 {} |
| 33 | +impl SimdCast for u8 {} |
22 | 34 | // Safety: primitive number types can be cast to other primitive number types
|
23 |
| -unsafe impl SimdCast for u16 {} |
| 35 | +unsafe impl Sealed for u16 {} |
| 36 | +impl SimdCast for u16 {} |
24 | 37 | // Safety: primitive number types can be cast to other primitive number types
|
25 |
| -unsafe impl SimdCast for u32 {} |
| 38 | +unsafe impl Sealed for u32 {} |
| 39 | +impl SimdCast for u32 {} |
26 | 40 | // Safety: primitive number types can be cast to other primitive number types
|
27 |
| -unsafe impl SimdCast for u64 {} |
| 41 | +unsafe impl Sealed for u64 {} |
| 42 | +impl SimdCast for u64 {} |
28 | 43 | // Safety: primitive number types can be cast to other primitive number types
|
29 |
| -unsafe impl SimdCast for usize {} |
| 44 | +unsafe impl Sealed for usize {} |
| 45 | +impl SimdCast for usize {} |
30 | 46 | // Safety: primitive number types can be cast to other primitive number types
|
31 |
| -unsafe impl SimdCast for f32 {} |
| 47 | +unsafe impl Sealed for f32 {} |
| 48 | +impl SimdCast for f32 {} |
32 | 49 | // Safety: primitive number types can be cast to other primitive number types
|
33 |
| -unsafe impl SimdCast for f64 {} |
34 |
| - |
35 |
| -/// Supporting trait for `Simd::cast_ptr`. Typically doesn't need to be used directly. |
36 |
| -/// |
37 |
| -/// # Safety |
38 |
| -/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast_ptr` |
39 |
| -/// intrinsic. |
40 |
| -pub unsafe trait SimdCastPtr<T> {} |
41 |
| - |
42 |
| -// Safety: pointers can be cast to other pointer types |
43 |
| -unsafe impl<T, U> SimdCastPtr<T> for *const U |
44 |
| -where |
45 |
| - U: core::ptr::Pointee, |
46 |
| - T: core::ptr::Pointee<Metadata = U::Metadata>, |
47 |
| -{ |
48 |
| -} |
49 |
| -// Safety: pointers can be cast to other pointer types |
50 |
| -unsafe impl<T, U> SimdCastPtr<T> for *mut U |
51 |
| -where |
52 |
| - U: core::ptr::Pointee, |
53 |
| - T: core::ptr::Pointee<Metadata = U::Metadata>, |
54 |
| -{ |
55 |
| -} |
| 50 | +unsafe impl Sealed for f64 {} |
| 51 | +impl SimdCast for f64 {} |
0 commit comments