From 4cdeba386ca3a98ece1cdb61f5318d4726573ca3 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Mon, 18 Apr 2016 17:50:29 -0400 Subject: [PATCH 1/2] Add .extract() for extracting underlying Vec --- src/array.rs | 6 ++++++ src/lib.rs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/array.rs b/src/array.rs index 996867a..a6394a3 100644 --- a/src/array.rs +++ b/src/array.rs @@ -144,6 +144,12 @@ impl Array { pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { IterMut { inner: self.data.iter_mut() } } + + /// Returns the underlying data vector for this Array in the + /// higher-dimensional equivalent of row-major order. + pub fn extract(self) -> Vec { + self.data + } } /// A trait implemented by types that can index into an `Array`. diff --git a/src/lib.rs b/src/lib.rs index 026f968..074ae3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,16 @@ mod tests { assert_eq!(2, a[1]); } + #[test] + fn test_extract() { + let a = Array::from_vec(vec![0i32, 1, 2], -1); + let a = a.extract(); + assert_eq!(a.len(), 3); + assert_eq!(0, a[0]); + assert_eq!(1, a[1]); + assert_eq!(2, a[2]); + } + #[test] fn test_2d_slice_get() { let mut a = Array::from_vec(vec![0i32, 1, 2], -1); From 4c57ea4058d807fb2e8e1049cda51e277e31beb5 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Mon, 18 Apr 2016 21:56:48 -0400 Subject: [PATCH 2/2] into_inner is most Rust=y --- src/array.rs | 2 +- src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/array.rs b/src/array.rs index a6394a3..d762932 100644 --- a/src/array.rs +++ b/src/array.rs @@ -147,7 +147,7 @@ impl Array { /// Returns the underlying data vector for this Array in the /// higher-dimensional equivalent of row-major order. - pub fn extract(self) -> Vec { + pub fn into_inner(self) -> Vec { self.data } } diff --git a/src/lib.rs b/src/lib.rs index 074ae3d..3108e57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,9 +49,9 @@ mod tests { } #[test] - fn test_extract() { + fn test_into_inner() { let a = Array::from_vec(vec![0i32, 1, 2], -1); - let a = a.extract(); + let a = a.into_inner(); assert_eq!(a.len(), 3); assert_eq!(0, a[0]); assert_eq!(1, a[1]); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy