Skip to content

Commit 336fb1a

Browse files
authored
Merge pull request #527 from jturner314/doc-more-conversions
Add table of conversions to/from Vecs and slices
2 parents ae13fd2 + fa78de1 commit 336fb1a

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/lib.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub type Ixs = isize;
237237
/// + [Subviews](#subviews)
238238
/// + [Arithmetic Operations](#arithmetic-operations)
239239
/// + [Broadcasting](#broadcasting)
240-
/// + [Conversions Between Array Types](#conversions-between-array-types)
240+
/// + [Conversions](#conversions)
241241
/// + [Constructor Methods for Owned Arrays](#constructor-methods-for-owned-arrays)
242242
/// + [Methods For All Array Types](#methods-for-all-array-types)
243243
///
@@ -650,7 +650,9 @@ pub type Ixs = isize;
650650
/// );
651651
/// ```
652652
///
653-
/// ## Conversions Between Array Types
653+
/// ## Conversions
654+
///
655+
/// ### Conversions Between Array Types
654656
///
655657
/// This table is a summary of the conversions between arrays of different
656658
/// ownership, dimensionality, and element type. All of the conversions in this
@@ -851,6 +853,32 @@ pub type Ixs = isize;
851853
/// </tr>
852854
/// </table>
853855
///
856+
/// ### Conversions Between Arrays and `Vec`s/Slices
857+
///
858+
/// This is a table of the safe conversions between arrays and `Vec`s/slices.
859+
/// Note that some of the return values are actually `Result`/`Option` wrappers
860+
/// around the indicated output types.
861+
///
862+
/// Input | Output | Methods
863+
/// ------|--------|--------
864+
/// `Vec<A>` | `ArrayBase<S: DataOwned, Ix1>` | [`::from_vec()`](#method.from_vec)
865+
/// `Vec<A>` | `ArrayBase<S: DataOwned, D>` | [`::from_shape_vec()`](#method.from_shape_vec)
866+
/// `&[A]` | `ArrayView<A, D>` | [`::from_shape()`](type.ArrayView.html#method.from_shape)
867+
/// `&mut [A]` | `ArrayViewMut<A, D>` | [`::from_shape()`](type.ArrayViewMut.html#method.from_shape)
868+
/// `&ArrayBase<S, Ix1>` | `Vec<A>` | [`.to_vec()`](#method.to_vec)
869+
/// `&ArrayBase<S, D>` | `&[A]` | [`.as_slice()`](#method.as_slice)<sup>[1](#req_contig_std)</sup>, [`.as_slice_memory_order()`](#method.as_slice_memory_order)<sup>[2](#req_contig)</sup>
870+
/// `&mut ArrayBase<S: DataMut, D>` | `&mut [A]` | [`.as_slice_mut()`](#method.as_slice_mut)<sup>[1](#req_contig_std)</sup>, [`.as_slice_memory_order_mut()`](#method.as_slice_memory_order_mut)<sup>[2](#req_contig)</sup>
871+
/// `ArrayView<A, D>` | `&[A]` | [`.into_slice()`](type.ArrayView.html#method.into_slice)
872+
/// `ArrayViewMut<A, D>` | `&mut [A]` | [`.into_slice()`](type.ArrayViewMut.html#method.into_slice)
873+
///
874+
/// <sup><a name="req_contig_std">1</a></sup>Works only if the array is
875+
/// contiguous and in standard order.
876+
///
877+
/// <sup><a name="req_contig">2</a></sup>Works only if the array is contiguous.
878+
///
879+
/// The table above does not include all the constructors; it only shows
880+
/// conversions to/from `Vec`s/slices. See below for more constructors.
881+
///
854882
/// [ArrayView::reborrow()]: type.ArrayView.html#method.reborrow
855883
/// [ArrayViewMut::reborrow()]: type.ArrayViewMut.html#method.reborrow
856884
/// [.into_dimensionality()]: #method.into_dimensionality

0 commit comments

Comments
 (0)