diff --git a/src/base/edition.rs b/src/base/edition.rs index 4a99b77f6..8bd6ad190 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -751,3 +751,25 @@ where self.data.extend(iter); } } + +/// Extend the number of rows of the `Vector` with elements from +/// a given iterator. +impl Extend for Matrix +where + N: Scalar, + S: Extend, +{ + /// Extend the number of rows of a `Vector` with elements + /// from the given iterator. + /// + /// # Example + /// ``` + /// use nalgebra::DVector; + /// let mut vector = DVector::from_vec(3, vec![0, 1, 2]); + /// vector.extend(vec![3, 4, 5]); + /// assert!(vector.eq(&DVector::from_vec(6, vec![0, 1, 2, 3, 4, 5]))); + /// ``` + fn extend>(&mut self, iter: I) { + self.data.extend(iter); + } +} diff --git a/src/base/matrix_vec.rs b/src/base/matrix_vec.rs index 8dfd940e5..b821afdb3 100644 --- a/src/base/matrix_vec.rs +++ b/src/base/matrix_vec.rs @@ -258,3 +258,14 @@ impl Extend for MatrixVec "The number of elements produced by the given iterator was not a multiple of the number of rows."); } } + +impl Extend for MatrixVec +{ + /// Extends the number of rows of the `MatrixVec` with elements + /// from the given iterator. + fn extend>(&mut self, iter: I) + { + self.data.extend(iter); + self.nrows = Dynamic::new(self.data.len()); + } +}