File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1284,3 +1284,40 @@ impl<T> MaybeUninit<T> {
1284
1284
}
1285
1285
}
1286
1286
}
1287
+
1288
+ impl < T , const N : usize > MaybeUninit < [ T ; N ] > {
1289
+ /// Transposes a `MaybeUninit<[T; N]>` into a `[MaybeUninit<T>; N]`.
1290
+ ///
1291
+ /// # Examples
1292
+ ///
1293
+ /// ```
1294
+ /// #![feature(maybe_uninit_uninit_array_transpose)]
1295
+ /// # use std::mem::MaybeUninit;
1296
+ ///
1297
+ /// let data: [MaybeUninit<u8>; 1000] = MaybeUninit::uninit().transpose();
1298
+ /// ```
1299
+ #[ unstable( feature = "maybe_uninit_uninit_array_transpose" , issue = "96097" ) ]
1300
+ pub fn transpose ( self ) -> [ MaybeUninit < T > ; N ] {
1301
+ // SAFETY: T and MaybeUninit<T> have the same layout
1302
+ unsafe { super :: transmute_copy ( & ManuallyDrop :: new ( self ) ) }
1303
+ }
1304
+ }
1305
+
1306
+ impl < T , const N : usize > [ MaybeUninit < T > ; N ] {
1307
+ /// Transposes a `[MaybeUninit<T>; N]` into a `MaybeUninit<[T; N]>`.
1308
+ ///
1309
+ /// # Examples
1310
+ ///
1311
+ /// ```
1312
+ /// #![feature(maybe_uninit_uninit_array_transpose)]
1313
+ /// # use std::mem::MaybeUninit;
1314
+ ///
1315
+ /// let data = [MaybeUninit::<u8>::uninit(); 1000];
1316
+ /// let data: MaybeUninit<[u8; 1000]> = data.transpose();
1317
+ /// ```
1318
+ #[ unstable( feature = "maybe_uninit_uninit_array_transpose" , issue = "96097" ) ]
1319
+ pub fn transpose ( self ) -> MaybeUninit < [ T ; N ] > {
1320
+ // SAFETY: T and MaybeUninit<T> have the same layout
1321
+ unsafe { super :: transmute_copy ( & ManuallyDrop :: new ( self ) ) }
1322
+ }
1323
+ }
You can’t perform that action at this time.
0 commit comments