From 3ce46de20e6b1b7f116a09b416f18ebe67bc713c Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 15:01:24 -0400 Subject: [PATCH 1/4] rename `into_slice` on ArrayView `to_slice` and deprecate existing method --- src/impl_views.rs | 11 +++++++++++ src/iterators/mod.rs | 2 +- src/lib.rs | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/impl_views.rs b/src/impl_views.rs index 98e324418..ec64bb906 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -137,6 +137,7 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. + #[deprecated(note="`into_slice` has been renamed to `to_slice`")] pub fn into_slice(&self) -> Option<&'a [A]> { if self.is_standard_layout() { unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) } @@ -145,6 +146,16 @@ where } } + /// Return the array’s data as a slice, if it is contiguous and in standard order. + /// Return `None` otherwise. + pub fn to_slice(&self) -> Option<&'a [A]> { + if self.is_standard_layout() { + unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) } + } else { + None + } + } + /// Converts to a raw array view. pub(crate) fn into_raw_view(self) -> RawArrayView { unsafe { RawArrayView::new_(self.ptr, self.dim, self.strides) } diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 22bc989c2..0f3f3de4d 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -264,7 +264,7 @@ where { pub(crate) fn new(self_: ArrayView<'a, A, D>) -> Self { Iter { - inner: if let Some(slc) = self_.into_slice() { + inner: if let Some(slc) = self_.to_slice() { ElementsRepr::Slice(slc.iter()) } else { ElementsRepr::Counted(self_.into_elements_base()) diff --git a/src/lib.rs b/src/lib.rs index 9741989d5..e8c512e93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -988,8 +988,8 @@ pub type Ixs = isize; /// `Array` | `Vec` | [`.into_raw_vec()`](type.Array.html#method.into_raw_vec)[1](#into_raw_vec) /// `&ArrayBase` | `&[A]` | [`.as_slice()`](#method.as_slice)[2](#req_contig_std), [`.as_slice_memory_order()`](#method.as_slice_memory_order)[3](#req_contig) /// `&mut ArrayBase` | `&mut [A]` | [`.as_slice_mut()`](#method.as_slice_mut)[2](#req_contig_std), [`.as_slice_memory_order_mut()`](#method.as_slice_memory_order_mut)[3](#req_contig) -/// `ArrayView` | `&[A]` | [`.into_slice()`](type.ArrayView.html#method.into_slice)[2](#req_contig_std) -/// `ArrayViewMut` | `&mut [A]` | [`.into_slice()`](type.ArrayViewMut.html#method.into_slice)[2](#req_contig_std) +/// `ArrayView` | `&[A]` | [`.to_slice()`](type.ArrayView.html#method.to_slice)[2](#req_contig_std) +/// `ArrayViewMut` | `&mut [A]` | [`.to_slice()`](type.ArrayViewMut.html#method.to_slice)[2](#req_contig_std) /// `Array0` | `A` | [`.into_scalar()`](type.Array.html#method.into_scalar) /// /// 1Returns the data in memory order. From 69522af364cc150576ebfa3e84c47232490479bd Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 15:24:21 -0400 Subject: [PATCH 2/4] fmt --- src/impl_views.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl_views.rs b/src/impl_views.rs index ec64bb906..ae97c5443 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -137,7 +137,7 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. - #[deprecated(note="`into_slice` has been renamed to `to_slice`")] + #[deprecated(note = "`into_slice` has been renamed to `to_slice`")] pub fn into_slice(&self) -> Option<&'a [A]> { if self.is_standard_layout() { unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) } From 25d04eb96154b264f23b2899ffdea25b9194d6ae Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Tue, 2 Jul 2019 16:37:32 +0300 Subject: [PATCH 3/4] Update src/impl_views.rs --- src/impl_views.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl_views.rs b/src/impl_views.rs index ae97c5443..b9d855b51 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -137,7 +137,7 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. - #[deprecated(note = "`into_slice` has been renamed to `to_slice`")] + #[deprecated(note = "`into_slice` has been renamed to `to_slice`", since="0.13.0")] pub fn into_slice(&self) -> Option<&'a [A]> { if self.is_standard_layout() { unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) } From a17613cda01a4346611e83ba7d981fa92fc56ac2 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Thu, 4 Jul 2019 23:59:44 +0300 Subject: [PATCH 4/4] Apply suggestions from code review --- src/impl_views.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl_views.rs b/src/impl_views.rs index b9d855b51..cfd65437f 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -137,7 +137,7 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. - #[deprecated(note = "`into_slice` has been renamed to `to_slice`", since="0.13.0")] + #[deprecated(note = "`into_slice` has been renamed to `to_slice`", since = "0.13.0")] pub fn into_slice(&self) -> Option<&'a [A]> { if self.is_standard_layout() { unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }