diff --git a/src/impl_views.rs b/src/impl_views.rs index 98e324418..cfd65437f 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`", 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())) } @@ -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.