1 //! Implements `From` and `Into` for vector types.
3 macro_rules
! impl_from_vector
{
4 ([$elem_ty
:ident
; $elem_count
:expr
]: $id
:ident
| $test_tt
:tt
6 impl From
<$source
> for $id
{
8 fn from(source
: $source
) -> Self {
9 fn static_assert_same_number_of_lanes
<T
, U
>()
11 T
: crate::sealed
::Simd
,
12 U
: crate::sealed
::Simd
<LanesType
= T
::LanesType
>,
15 use crate::llvm
::simd_cast
;
16 static_assert_same_number_of_lanes
::<$id
, $source
>();
17 Simd(unsafe { simd_cast(source.0) }
)
21 // FIXME: `Into::into` is not inline, but due to the blanket impl in
22 // `std`, which is not marked `default`, we cannot override it here
23 // with specialization.
26 impl Into<$id> for $source {
28 fn into(self) -> $id {
29 unsafe { simd_cast(self) }
37 pub mod [<$id _from_ $source
>] {
39 #[cfg_attr(not(target_arch = "wasm32"), test)]
40 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
42 assert_eq
!($id
::lanes(), $source
::lanes());
43 let source
: $source
= Default
::default();
44 let vec
: $id
= Default
::default();
46 let e
= $id
::from(source
);
49 let e
: $id
= source
.into();
58 macro_rules
! impl_from_vectors
{
59 ([$elem_ty
:ident
; $elem_count
:expr
]: $id
:ident
| $test_tt
:tt
60 | $
($source
:ident
),*) => {
63 [$elem_ty
; $elem_count
]: $id
| $test_tt
| $source