diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2022-11-11 17:32:48 -0500 |
|---|---|---|
| committer | Caleb Zulawski <caleb.zulawski@gmail.com> | 2022-11-11 17:32:48 -0500 |
| commit | 7ac1fbbcb14c05f778cf1c550e2b30f00606bb97 (patch) | |
| tree | bab2c8fcbaacc5de56fbdc001ae1abce74833e27 | |
| parent | ecc28752e871af8886a49fdefdf4733a2dae8aac (diff) | |
| download | rust-7ac1fbbcb14c05f778cf1c550e2b30f00606bb97.tar.gz rust-7ac1fbbcb14c05f778cf1c550e2b30f00606bb97.zip | |
impl TryFrom<&[T]> for Simd
| -rw-r--r-- | crates/core_simd/src/vector.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index c5d68f1b921..0095ed1648f 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -650,6 +650,30 @@ where } } +impl<T, const LANES: usize> TryFrom<&[T]> for Simd<T, LANES> +where + LaneCount<LANES>: SupportedLaneCount, + T: SimdElement, +{ + type Error = core::array::TryFromSliceError; + + fn try_from(slice: &[T]) -> Result<Self, Self::Error> { + Ok(Self::from_array(slice.try_into()?)) + } +} + +impl<T, const LANES: usize> TryFrom<&mut [T]> for Simd<T, LANES> +where + LaneCount<LANES>: SupportedLaneCount, + T: SimdElement, +{ + type Error = core::array::TryFromSliceError; + + fn try_from(slice: &mut [T]) -> Result<Self, Self::Error> { + Ok(Self::from_array(slice.try_into()?)) + } +} + mod sealed { pub trait Sealed {} } |
