File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 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> {
13991399 }
14001400}
14011401
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+
14021427impl < T : Copy > Option < & T > {
14031428 /// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
14041429 /// option.
You can’t perform that action at this time.
0 commit comments