From 43747b4f598eeed44d9ee7e9787a9d451ab8681d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 29 Nov 2019 15:31:52 +0100 Subject: [PATCH] Implement Extend<&N> for VecStorage. Extend was already implemented, but nalgebra vectors/matrices give iterators that give &N, not N, so implementing Extend<&N> as well makes it easier to use. It seems common practice to do so: The standard library's Vec also implments Extend for both T and &T. --- src/base/vec_storage.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index a0230488..747e5179 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -268,6 +268,21 @@ impl Extend for VecStorage } } +impl<'a, N: 'a + Copy, R: Dim> Extend<&'a N> for VecStorage +{ + /// Extends the number of columns of the `VecStorage` with elements + /// from the given iterator. + /// + /// # Panics + /// This function panics if the number of elements yielded by the + /// given iterator is not a multiple of the number of rows of the + /// `VecStorage`. + fn extend>(&mut self, iter: I) + { + self.extend(iter.into_iter().copied()) + } +} + impl Extend> for VecStorage where N: Scalar + Copy,