Skip to content

Commit 7ac1fbb

Browse files
committed
impl TryFrom<&[T]> for Simd
1 parent ecc2875 commit 7ac1fbb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

crates/core_simd/src/vector.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,30 @@ where
650650
}
651651
}
652652

653+
impl<T, const LANES: usize> TryFrom<&[T]> for Simd<T, LANES>
654+
where
655+
LaneCount<LANES>: SupportedLaneCount,
656+
T: SimdElement,
657+
{
658+
type Error = core::array::TryFromSliceError;
659+
660+
fn try_from(slice: &[T]) -> Result<Self, Self::Error> {
661+
Ok(Self::from_array(slice.try_into()?))
662+
}
663+
}
664+
665+
impl<T, const LANES: usize> TryFrom<&mut [T]> for Simd<T, LANES>
666+
where
667+
LaneCount<LANES>: SupportedLaneCount,
668+
T: SimdElement,
669+
{
670+
type Error = core::array::TryFromSliceError;
671+
672+
fn try_from(slice: &mut [T]) -> Result<Self, Self::Error> {
673+
Ok(Self::from_array(slice.try_into()?))
674+
}
675+
}
676+
653677
mod sealed {
654678
pub trait Sealed {}
655679
}

0 commit comments

Comments
 (0)