From dd92d7e4cfccb6b280a0388bca60cb68d3edef13 Mon Sep 17 00:00:00 2001 From: Armin Becher Date: Fri, 24 Apr 2020 09:42:43 +0200 Subject: [PATCH] Add flatten --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 09b38b5..fcf4d90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -603,6 +603,22 @@ impl Grid { } self.cols += 1; } + + /// Returns a reference to the internal data structure of the grid. + /// + /// Grid uses a row major layout. + /// All rows are placed right after each other in the vector data structure. + /// + /// # Examples + /// ``` + /// use grid::*; + /// let grid = grid![[1,2,3][4,5,6]]; + /// let flat = grid.flatten(); + /// assert_eq!(flat, &vec![1,2,3,4,5,6]); + /// ``` + pub fn flatten(&self) -> &Vec { + return &self.data + } } impl Clone for Grid {