Skip to content

Commit 5098a69

Browse files
max-sixtyLukeMathWalker
authored andcommitted
rename into_slice on ArrayView to_slice (#646)
* rename `into_slice` on ArrayView `to_slice` and deprecate existing method * fmt * Update src/impl_views.rs * Apply suggestions from code review
1 parent beb537c commit 5098a69

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/impl_views.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ where
137137

138138
/// Return the array’s data as a slice, if it is contiguous and in standard order.
139139
/// Return `None` otherwise.
140+
#[deprecated(note = "`into_slice` has been renamed to `to_slice`", since = "0.13.0")]
140141
pub fn into_slice(&self) -> Option<&'a [A]> {
141142
if self.is_standard_layout() {
142143
unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }
@@ -145,6 +146,16 @@ where
145146
}
146147
}
147148

149+
/// Return the array’s data as a slice, if it is contiguous and in standard order.
150+
/// Return `None` otherwise.
151+
pub fn to_slice(&self) -> Option<&'a [A]> {
152+
if self.is_standard_layout() {
153+
unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }
154+
} else {
155+
None
156+
}
157+
}
158+
148159
/// Converts to a raw array view.
149160
pub(crate) fn into_raw_view(self) -> RawArrayView<A, D> {
150161
unsafe { RawArrayView::new_(self.ptr, self.dim, self.strides) }

src/iterators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ where
264264
{
265265
pub(crate) fn new(self_: ArrayView<'a, A, D>) -> Self {
266266
Iter {
267-
inner: if let Some(slc) = self_.into_slice() {
267+
inner: if let Some(slc) = self_.to_slice() {
268268
ElementsRepr::Slice(slc.iter())
269269
} else {
270270
ElementsRepr::Counted(self_.into_elements_base())

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,8 @@ pub type Ixs = isize;
988988
/// `Array<A, D>` | `Vec<A>` | [`.into_raw_vec()`](type.Array.html#method.into_raw_vec)<sup>[1](#into_raw_vec)</sup>
989989
/// `&ArrayBase<S, D>` | `&[A]` | [`.as_slice()`](#method.as_slice)<sup>[2](#req_contig_std)</sup>, [`.as_slice_memory_order()`](#method.as_slice_memory_order)<sup>[3](#req_contig)</sup>
990990
/// `&mut ArrayBase<S: DataMut, D>` | `&mut [A]` | [`.as_slice_mut()`](#method.as_slice_mut)<sup>[2](#req_contig_std)</sup>, [`.as_slice_memory_order_mut()`](#method.as_slice_memory_order_mut)<sup>[3](#req_contig)</sup>
991-
/// `ArrayView<A, D>` | `&[A]` | [`.into_slice()`](type.ArrayView.html#method.into_slice)<sup>[2](#req_contig_std)</sup>
992-
/// `ArrayViewMut<A, D>` | `&mut [A]` | [`.into_slice()`](type.ArrayViewMut.html#method.into_slice)<sup>[2](#req_contig_std)</sup>
991+
/// `ArrayView<A, D>` | `&[A]` | [`.to_slice()`](type.ArrayView.html#method.to_slice)<sup>[2](#req_contig_std)</sup>
992+
/// `ArrayViewMut<A, D>` | `&mut [A]` | [`.to_slice()`](type.ArrayViewMut.html#method.to_slice)<sup>[2](#req_contig_std)</sup>
993993
/// `Array0<A>` | `A` | [`.into_scalar()`](type.Array.html#method.into_scalar)
994994
///
995995
/// <sup><a name="into_raw_vec">1</a></sup>Returns the data in memory order.

0 commit comments

Comments
 (0)