Skip to content

Make build_uninit public #1001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2021
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
19 changes: 10 additions & 9 deletions src/impl_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ where
/// ### 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/read with the element type `A`.
///
/// ### Examples
///
Expand Down Expand Up @@ -580,10 +580,10 @@ where
/// The uninitialized elements of type `A` are represented by the type `MaybeUninit<A>`,
/// an easier way to handle uninit values correctly.
///
/// The `builder` closure gets unshared access to the array through a raw view
/// and can use it to modify the array before it is returned. This allows initializing
/// the array for any owned array type (avoiding clone requirements for copy-on-write,
/// because the array is unshared when initially created).
/// The `builder` closure gets unshared access to the array through a view and can use it to
/// modify the array before it is returned. This allows initializing the array for any owned
/// array type (avoiding clone requirements for copy-on-write, because the array is unshared
/// when initially created).
///
/// Only *when* the array is completely initialized with valid elements, can it be
/// converted to an array of `A` elements using [`.assume_init()`].
Expand All @@ -593,17 +593,18 @@ where
/// ### 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/read with the element type `A`.
///
pub(crate) fn build_uninit<Sh, F>(shape: Sh, builder: F) -> ArrayBase<S::MaybeUninit, D>
/// [`.assume_init()`]: ArrayBase::assume_init
pub fn build_uninit<Sh, F>(shape: Sh, builder: F) -> ArrayBase<S::MaybeUninit, D>
where
Sh: ShapeBuilder<Dim = D>,
F: FnOnce(RawArrayViewMut<MaybeUninit<A>, D>),
F: FnOnce(ArrayViewMut<MaybeUninit<A>, D>),
{
let mut array = Self::uninit(shape);
// Safe because: the array is unshared here
unsafe {
builder(array.raw_view_mut_unchecked());
builder(array.raw_view_mut_unchecked().deref_into_view_mut());
}
array
}
Expand Down
2 changes: 1 addition & 1 deletion src/zip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ macro_rules! map_impl {
// Use partial to count the number of filled elements, and can drop the right
// number of elements on unwinding (if it happens during apply/collect).
unsafe {
let output_view = output.cast::<R>();
let output_view = output.into_raw_view_mut().cast::<R>();
self.and(output_view)
.collect_with_partial(f)
.release_ownership();
Expand Down