File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1399,6 +1399,31 @@ impl<T> Option<T> {
1399
1399
}
1400
1400
}
1401
1401
1402
+ impl < T , U > Option < ( T , U ) > {
1403
+ /// Unzips an option containing a tuple of two options
1404
+ ///
1405
+ /// If `self` is `Some((a, b))` this method returns `(Some(a), Some(b))`.
1406
+ /// Otherwise, `(None, None)` is returned.
1407
+ ///
1408
+ /// # Examples
1409
+ ///
1410
+ /// ```
1411
+ /// let x = Some((1, "hi"));
1412
+ /// let y = None::<(u8, u32)>;
1413
+ ///
1414
+ /// assert_eq!(x.unzip(), (Some(1), Some("hi")));
1415
+ /// assert_eq!(y.unzip(), (None, None));
1416
+ /// ```
1417
+ #[ inline]
1418
+ #[ unstable( feature = "unzip_option" , issue = "none" , reason = "recently added" ) ]
1419
+ pub const fn unzip ( self ) -> ( Option < T > , Option < U > ) {
1420
+ match self {
1421
+ Some ( ( a, b) ) => ( Some ( a) , Some ( b) ) ,
1422
+ None => ( None , None ) ,
1423
+ }
1424
+ }
1425
+ }
1426
+
1402
1427
impl < T : Copy > Option < & T > {
1403
1428
/// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
1404
1429
/// option.
You can’t perform that action at this time.
0 commit comments