From 68b7d21828b90f57512ed575a6267f08bb7af3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 11 Apr 2017 00:13:28 +0200 Subject: [PATCH] Implement IntoIterator for &Matrix and &mut Matrix IntoIterator for Matrix will beharder to implement. Partially addresses #241. --- src/core/conversion.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/core/conversion.rs b/src/core/conversion.rs index 2ed03ece..fb0a48be 100644 --- a/src/core/conversion.rs +++ b/src/core/conversion.rs @@ -7,7 +7,8 @@ use alga::general::{SubsetOf, SupersetOf}; use core::{Scalar, Matrix}; use core::dimension::{Dim, DimName, DimNameMul, DimNameProd, U1, U2, U3, U4, U5, U6}; use core::constraint::{ShapeConstraint, SameNumberOfRows, SameNumberOfColumns}; -use core::storage::OwnedStorage; +use core::storage::{Storage, StorageMut, OwnedStorage}; +use core::iter::{MatrixIter, MatrixIterMut}; use core::allocator::{OwnedAllocator, SameShapeAllocator}; @@ -62,6 +63,26 @@ impl SubsetOf> for Matrix } } +impl<'a, N: Scalar, R: Dim, C: Dim, S: Storage> IntoIterator for &'a Matrix { + type Item = &'a N; + type IntoIter = MatrixIter<'a, N, R, C, S>; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> IntoIterator for &'a mut Matrix { + type Item = &'a mut N; + type IntoIter = MatrixIterMut<'a, N, R, C, S>; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + self.iter_mut() + } +} + macro_rules! impl_from_into_asref_1D( ($($Dim: ident => $SZ: expr);* $(;)*) => {$(