Skip to content

Commit 946233c

Browse files
committed
Add recommend changes to array
Switch from indexing to zip, and also use `write` on `MaybeUninit`. Add array_map feature to core/src/lib Attempt to fix issue of no such feature
1 parent 2183237 commit 946233c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

library/core/src/array/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ impl<T, const N: usize> [T; N] {
372372
///
373373
/// # Examples
374374
/// ```
375+
/// #![feature(array_map)]
375376
/// let x = [1,2,3];
376377
/// let y = x.map(|v| v + 1);
377378
/// assert_eq!(y, [2,3,4]);
@@ -402,8 +403,8 @@ impl<T, const N: usize> [T; N] {
402403
}
403404
let mut dst = MaybeUninit::uninit_array::<N>();
404405
let mut guard: Guard<S, N> = Guard { dst: &mut dst as *mut _ as *mut S, curr_init: 0 };
405-
for (i, e) in IntoIter::new(self).enumerate() {
406-
dst[i] = MaybeUninit::new(f(e));
406+
for (src, dst) in IntoIter::new(self).zip(&mut dst) {
407+
dst.write(f(src));
407408
guard.curr_init += 1;
408409
}
409410
// FIXME convert to crate::mem::transmute when works with generics

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
#![feature(abi_unadjusted)]
146146
#![feature(adx_target_feature)]
147147
#![feature(maybe_uninit_slice)]
148+
#![feature(maybe_uninit_extra)]
148149
#![feature(external_doc)]
149150
#![feature(associated_type_bounds)]
150151
#![feature(const_caller_location)]

0 commit comments

Comments
 (0)