File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2545,3 +2545,27 @@ impl<T> Option<Option<T>> {
2545
2545
}
2546
2546
}
2547
2547
}
2548
+
2549
+ impl < T , const N : usize > [ Option < T > ; N ] {
2550
+ /// Transposes a `[Option<T>; N]` into a `Option<[T; N]>`.
2551
+ ///
2552
+ /// # Examples
2553
+ ///
2554
+ /// ```
2555
+ /// #![feature(option_array_transpose)]
2556
+ /// # use std::option::Option;
2557
+ ///
2558
+ /// let data = [Some(0); 1000];
2559
+ /// let data: Option<[u8; 1000]> = data.transpose();
2560
+ /// assert_eq!(data, Some([0; 1000]));
2561
+ ///
2562
+ /// let data = [Some(0), None];
2563
+ /// let data: Option<[u8; 2]> = data.transpose();
2564
+ /// assert_eq!(data, None);
2565
+ /// ```
2566
+ #[ inline]
2567
+ #[ unstable( feature = "option_array_transpose" , issue = "130828" ) ]
2568
+ pub fn transpose ( self ) -> Option < [ T ; N ] > {
2569
+ self . try_map ( core:: convert:: identity)
2570
+ }
2571
+ }
You can’t perform that action at this time.
0 commit comments