1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
//! Fixed size arrays usable for sparse matrices. //! //! Mainly useful to create a sparse matrix view over a sparse vector //! without allocation. use std::ops::{Deref, DerefMut}; /// Wrapper around a size 2 array, with `Deref` implementation. pub struct Array2<T> { pub data: [T; 2], } impl<T> Deref for Array2<T> { type Target = [T]; fn deref(&self) -> &[T] { &self.data[..] } } impl<T> DerefMut for Array2<T> { fn deref_mut(&mut self) -> &mut [T] { &mut self.data[..] } }