8000 rename `into_slice` on ArrayView `to_slice` by max-sixty · Pull Request #646 · rust-ndarray/ndarray · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/impl_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())) }
Expand All @@ -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<A, D> {
unsafe { RawArrayView::new_(self.ptr, self.dim, self.strides) }
Expand Down
2 changes: 1 addition & 1 deletion src/iterators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ where
{
pub(cra B1A4 te) 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())
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,8 @@ pub type Ixs = isize;
/// `Array<A, D>` | `Vec<A>` | [`.into_raw_vec()`](type.Array.html#method.into_raw_vec)<sup>[1](#into_raw_vec)</sup>
/// `&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>
/// `&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>
/// `ArrayView<A, D>` | `&[A]` | [`.into_slice()`](type.ArrayView.html#method.into_slice)<sup>[2](#req_contig_std)</sup>
/// `ArrayViewMut<A, D>` | `&mut [A]` | [`.into_slice()`](type.ArrayViewMut.html#method.into_slice)<sup>[2](#req_contig_std)</sup>
/// `ArrayView<A, D>` | `&[A]` | [`.to_slice()`](type.ArrayView.html#method.to_slice)<sup>[2](#req_contig_std)</sup>
/// `ArrayViewMut<A, D>` | `&mut [A]` | [`.to_slice()`](type.ArrayViewMut.html#method.to_slice)<sup>[2](#req_contig_std)</sup>
/// `Array0<A>` | `A` | [`.into_scalar()`](type.Array.html#method.into_scalar)
///
/// <sup><a name="into_raw_vec">1</a></sup>Returns the data in memory order.
Expand Down
0