Skip to content

Commit

Permalink
DOC: Update doc for maybe_uninit and .assume_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Apr 18, 2020
1 parent 0275934 commit 1650601
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/impl_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,22 @@ where
/// an easier way to handle uninit values correctly.
///
/// Only *when* the array is completely initialized with valid elements, can it be
/// converted to an array of `A` elements using [`assume_init()`].
/// converted to an array of `A` elements using [`.assume_init()`].
///
/// **Panics** if the number of elements in `shape` would overflow isize.
///
/// ### Safety
///
/// The whole of the array must be initialized before it is converted
/// using [`assume_init()`] or otherwise traversed.
/// using [`.assume_init()`] or otherwise traversed.
///
/// ### Examples
///
/// It is possible to assign individual values through `*elt = MaybeUninit::new(value)`
/// and so on.
///
/// [`.assume_init()`]: ArrayBase::assume_init
///
/// ```
/// use ndarray::{s, Array2};
/// use ndarray::Zip;
Expand Down
10 changes: 9 additions & 1 deletion src/impl_special_element_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ where
/// **Promise** that the array's elements are all fully initialized, and convert
/// the array from element type `MaybeUninit<A>` to `A`.
///
/// For owned arrays, the promise must include all of the Array's storage
/// For example, it can convert an `Array<MaybeUninit<f64>, D>` to `Array<f64, D>`.
///
/// ## Safety
///
/// Safe to use if all the array's elements have been initialized.
///
/// Note that for owned and shared ownership arrays, the promise must include all of the
/// array's storage; it is for example possible to slice these in place, but that must
/// only be done after all elements have been initialized.
pub unsafe fn assume_init(self) -> ArrayBase<<S as RawDataSubst<A>>::Output, D> {
// NOTE: Fully initialized includes elements not reachable in current slicing/view.

Expand Down

0 comments on commit 1650601

Please sign in to comment.