Skip to content

Commit cbf12d2

Browse files
authored
Merge pull request #1001 from rust-ndarray/build-uninit
Make build_uninit public
2 parents 28e4d4c + a023832 commit cbf12d2

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/impl_constructors.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ where
530530
/// ### Safety
531531
///
532532
/// The whole of the array must be initialized before it is converted
533-
/// using [`.assume_init()`] or otherwise traversed.
533+
/// using [`.assume_init()`] or otherwise traversed/read with the element type `A`.
534534
///
535535
/// ### Examples
536536
///
@@ -580,10 +580,10 @@ where
580580
/// The uninitialized elements of type `A` are represented by the type `MaybeUninit<A>`,
581581
/// an easier way to handle uninit values correctly.
582582
///
583-
/// The `builder` closure gets unshared access to the array through a raw view
584-
/// and can use it to modify the array before it is returned. This allows initializing
585-
/// the array for any owned array type (avoiding clone requirements for copy-on-write,
586-
/// because the array is unshared when initially created).
583+
/// The `builder` closure gets unshared access to the array through a view and can use it to
584+
/// modify the array before it is returned. This allows initializing the array for any owned
585+
/// array type (avoiding clone requirements for copy-on-write, because the array is unshared
586+
/// when initially created).
587587
///
588588
/// Only *when* the array is completely initialized with valid elements, can it be
589589
/// converted to an array of `A` elements using [`.assume_init()`].
@@ -593,17 +593,18 @@ where
593593
/// ### Safety
594594
///
595595
/// The whole of the array must be initialized before it is converted
596-
/// using [`.assume_init()`] or otherwise traversed.
596+
/// using [`.assume_init()`] or otherwise traversed/read with the element type `A`.
597597
///
598-
pub(crate) fn build_uninit<Sh, F>(shape: Sh, builder: F) -> ArrayBase<S::MaybeUninit, D>
598+
/// [`.assume_init()`]: ArrayBase::assume_init
599+
pub fn build_uninit<Sh, F>(shape: Sh, builder: F) -> ArrayBase<S::MaybeUninit, D>
599600
where
600601
Sh: ShapeBuilder<Dim = D>,
601-
F: FnOnce(RawArrayViewMut<MaybeUninit<A>, D>),
602+
F: FnOnce(ArrayViewMut<MaybeUninit<A>, D>),
602603
{
603604
let mut array = Self::uninit(shape);
604605
// Safe because: the array is unshared here
605606
unsafe {
606-
builder(array.raw_view_mut_unchecked());
607+
builder(array.raw_view_mut_unchecked().deref_into_view_mut());
607608
}
608609
array
609610
}

src/zip/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ macro_rules! map_impl {
745745
// Use partial to count the number of filled elements, and can drop the right
746746
// number of elements on unwinding (if it happens during apply/collect).
747747
unsafe {
748-
let output_view = output.cast::<R>();
748+
let output_view = output.into_raw_view_mut().cast::<R>();
749749
self.and(output_view)
750750
.collect_with_partial(f)
751751
.release_ownership();

0 commit comments

Comments
 (0)