Skip to content

Commit db63a79

Browse files
committed
API: Un-deprecate ArrayView::into_slice and deprecate ArrayView::to_slice
Looking closely at this one, it's actually clear why it should be called into_slice (and why it was called so from the start). There is already a general `ArrayBase::as_slice`. 1. `ArrayView<'a, _>::into_slice(self) -> Option<&'a [A]>` is an extra feature on top of the generic `as_slice` because exactly: we preserve the lifetime parameter from the view to the slice. 2. We relax the input parameter from `self` to `&self` because it makes only makes the method apply in more places and copy less data The "into" semantic is exactly that the lifetime parameter is preserved from the array view into the slice. Clippy is just a robot, it didn't understand this.
1 parent e585262 commit db63a79

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/impl_views/conversions.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ where
3131

3232
/// Return the array’s data as a slice, if it is contiguous and in standard order.
3333
/// Return `None` otherwise.
34-
#[deprecated(note = "`into_slice` has been renamed to `to_slice`", since = "0.13.0")]
3534
#[allow(clippy::wrong_self_convention)]
3635
pub fn into_slice(&self) -> Option<&'a [A]> {
3736
if self.is_standard_layout() {
@@ -43,12 +42,9 @@ where
4342

4443
/// Return the array’s data as a slice, if it is contiguous and in standard order.
4544
/// Return `None` otherwise.
45+
#[deprecated(note = "`to-slice` has been deprecated in favour of `into_slice`", since = "0.15.0")]
4646
pub fn to_slice(&self) -> Option<&'a [A]> {
47-
if self.is_standard_layout() {
48-
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
49-
} else {
50-
None
51-
}
47+
self.into_slice()
5248
}
5349

5450
/// Converts to a raw array view.

src/iterators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ where
279279
{
280280
pub(crate) fn new(self_: ArrayView<'a, A, D>) -> Self {
281281
Iter {
282-
inner: if let Some(slc) = self_.to_slice() {
282+
inner: if let Some(slc) = self_.into_slice() {
283283
ElementsRepr::Slice(slc.iter())
284284
} else {
285285
ElementsRepr::Counted(self_.into_elements_base())

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ pub type Ixs = isize;
996996
/// `Array<A, D>` | `Vec<A>` | [`.into_raw_vec()`](type.Array.html#method.into_raw_vec)<sup>[1](#into_raw_vec)</sup>
997997
/// `&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>
998998
/// `&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>
999-
/// `ArrayView<A, D>` | `&[A]` | [`.to_slice()`](type.ArrayView.html#method.to_slice)<sup>[2](#req_contig_std)</sup>
999+
/// `ArrayView<A, D>` | `&[A]` | [`.into_slice()`](type.ArrayView.html#method.into_slice)<sup>[2](#req_contig_std)</sup>
10001000
/// `ArrayViewMut<A, D>` | `&mut [A]` | [`.into_slice()`](type.ArrayViewMut.html#method.into_slice)<sup>[2](#req_contig_std)</sup>
10011001
/// `Array0<A>` | `A` | [`.into_scalar()`](type.Array.html#method.into_scalar)
10021002
///

0 commit comments

Comments
 (0)