impl TryFrom<&[T]> for Simd

This commit is contained in:
Caleb Zulawski 2022-11-11 17:32:48 -05:00
parent ecc28752e8
commit 7ac1fbbcb1

View File

@ -650,6 +650,30 @@ fn from(vector: Simd<T, LANES>) -> Self {
}
}
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 {}
}