Skip to content

Commit 1650601

Browse files
committed
DOC: Update doc for maybe_uninit and .assume_init()
1 parent 0275934 commit 1650601

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/impl_constructors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -533,20 +533,22 @@ where
533533
/// an easier way to handle uninit values correctly.
534534
///
535535
/// Only *when* the array is completely initialized with valid elements, can it be
536-
/// converted to an array of `A` elements using [`assume_init()`].
536+
/// converted to an array of `A` elements using [`.assume_init()`].
537537
///
538538
/// **Panics** if the number of elements in `shape` would overflow isize.
539539
///
540540
/// ### Safety
541541
///
542542
/// The whole of the array must be initialized before it is converted
543-
/// using [`assume_init()`] or otherwise traversed.
543+
/// using [`.assume_init()`] or otherwise traversed.
544544
///
545545
/// ### Examples
546546
///
547547
/// It is possible to assign individual values through `*elt = MaybeUninit::new(value)`
548548
/// and so on.
549549
///
550+
/// [`.assume_init()`]: ArrayBase::assume_init
551+
///
550552
/// ```
551553
/// use ndarray::{s, Array2};
552554
/// use ndarray::Zip;

src/impl_special_element_types.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ where
2727
/// **Promise** that the array's elements are all fully initialized, and convert
2828
/// the array from element type `MaybeUninit<A>` to `A`.
2929
///
30-
/// For owned arrays, the promise must include all of the Array's storage
30+
/// For example, it can convert an `Array<MaybeUninit<f64>, D>` to `Array<f64, D>`.
31+
///
32+
/// ## Safety
33+
///
34+
/// Safe to use if all the array's elements have been initialized.
35+
///
36+
/// Note that for owned and shared ownership arrays, the promise must include all of the
37+
/// array's storage; it is for example possible to slice these in place, but that must
38+
/// only be done after all elements have been initialized.
3139
pub unsafe fn assume_init(self) -> ArrayBase<<S as RawDataSubst<A>>::Output, D> {
3240
// NOTE: Fully initialized includes elements not reachable in current slicing/view.
3341

0 commit comments

Comments
 (0)