From f715883f9f17e35ed511741300bd4319145d1d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 21 Nov 2021 21:47:35 +0100 Subject: [PATCH] Re-add the conversion from a slice to a static array --- src/base/conversion.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 7b2159f1..dd71186f 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -23,7 +23,7 @@ use crate::base::{ use crate::base::{DVector, RowDVector, VecStorage}; use crate::base::{SliceStorage, SliceStorageMut}; use crate::constraint::DimEq; -use crate::{IsNotStaticOne, RowSVector, SMatrix, SVector}; +use crate::{IsNotStaticOne, RowSVector, SMatrix, SVector, VectorSlice, VectorSliceMut}; use std::mem::MaybeUninit; // TODO: too bad this won't work for slice conversions. @@ -125,6 +125,24 @@ impl From> for [T; D] { } } +impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const D: usize> + From, RStride, CStride>> for [T; D] +{ + #[inline] + fn from(vec: VectorSlice<'a, T, Const, RStride, CStride>) -> Self { + vec.into_owned().into() + } +} + +impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const D: usize> + From, RStride, CStride>> for [T; D] +{ + #[inline] + fn from(vec: VectorSliceMut<'a, T, Const, RStride, CStride>) -> Self { + vec.into_owned().into() + } +} + impl From<[T; D]> for RowSVector where Const: IsNotStaticOne, @@ -197,8 +215,26 @@ impl From<[[T; R]; C]> for SMatrix From> for [[T; R]; C] { #[inline] - fn from(vec: SMatrix) -> Self { - vec.data.0 + fn from(mat: SMatrix) -> Self { + mat.data.0 + } +} + +impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize> + From, Const, RStride, CStride>> for [[T; R]; C] +{ + #[inline] + fn from(mat: MatrixSlice<'a, T, Const, Const, RStride, CStride>) -> Self { + mat.into_owned().into() + } +} + +impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize> + From, Const, RStride, CStride>> for [[T; R]; C] +{ + #[inline] + fn from(mat: MatrixSliceMut<'a, T, Const, Const, RStride, CStride>) -> Self { + mat.into_owned().into() } }