Skip to content

Commit 8d3e93b

Browse files
committed
Auto merge of #47622 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 10 pull requests - Successful merges: #46938, #47193, #47508, #47510, #47532, #47535, #47559, #47568, #47573, #47578 - Failed merges:
2 parents b85aefb + 4074893 commit 8d3e93b

File tree

20 files changed

+388
-201
lines changed

20 files changed

+388
-201
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ It's absolutely fine to have multiple build directories with different
301301
[pull-requests]: #pull-requests
302302

303303
Pull requests are the primary mechanism we use to change Rust. GitHub itself
304-
has some [great documentation][pull-requests] on using the Pull Request feature.
304+
has some [great documentation][about-pull-requests] on using the Pull Request feature.
305305
We use the "fork and pull" model [described here][development-models], where
306306
contributors push changes to their personal fork and create pull requests to
307307
bring those changes into the source repository.
308308

309-
[pull-requests]: https://help.github.com/articles/about-pull-requests/
309+
[about-pull-requests]: https://help.github.com/articles/about-pull-requests/
310310
[development-models]: https://help.github.com/articles/about-collaborative-development-models/
311311

312312
Please make pull requests against the `master` branch.

src/doc/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Rust provides a number of book-length sets of documentation, collectively
2828
nicknamed 'The Rust Bookshelf.'
2929

3030
* [The Rust Programming Language][book] teaches you how to program in Rust.
31+
* [Rust By Example][rbe] teaches you how to program in Rust using editable examples.
3132
* [The Cargo Book][cargo-book] is a guide to Cargo, Rust's build tool and dependency manager.
3233
* [The Unstable Book][unstable-book] has documentation for unstable features.
3334
* [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust.
@@ -51,6 +52,7 @@ before this policy was put into place. That work is being tracked
5152
[refchecklist]: https://github.com/rust-lang-nursery/reference/issues/9
5253
[err]: error-index.html
5354
[book]: book/index.html
55+
[rbe]: rust-by-example/index.html
5456
[nomicon]: nomicon/index.html
5557
[unstable-book]: unstable-book/index.html
5658
[rustdoc-book]: rustdoc/index.html

src/libcore/option.rs

+29
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,35 @@ impl<T: Default> Option<T> {
881881
}
882882
}
883883

884+
impl<T, E> Option<Result<T, E>> {
885+
/// Transposes an `Option` of a `Result` into a `Result` of an `Option`.
886+
///
887+
/// `None` will be mapped to `Ok(None)`.
888+
/// `Some(Ok(_))` and `Some(Err(_))` will be mapped to `Ok(Some(_))` and `Err(_)`.
889+
///
890+
/// # Examples
891+
///
892+
/// ```
893+
/// #![feature(transpose_result)]
894+
///
895+
/// #[derive(Debug, Eq, PartialEq)]
896+
/// struct SomeErr;
897+
///
898+
/// let x: Result<Option<i32>, SomeErr> = Ok(Some(5));
899+
/// let y: Option<Result<i32, SomeErr>> = Some(Ok(5));
900+
/// assert_eq!(x, y.transpose());
901+
/// ```
902+
#[inline]
903+
#[unstable(feature = "transpose_result", issue = "47338")]
904+
pub fn transpose(self) -> Result<Option<T>, E> {
905+
match self {
906+
Some(Ok(x)) => Ok(Some(x)),
907+
Some(Err(e)) => Err(e),
908+
None => Ok(None),
909+
}
910+
}
911+
}
912+
884913
// This is a separate function to reduce the code size of .expect() itself.
885914
#[inline(never)]
886915
#[cold]

src/libcore/result.rs

+29
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,35 @@ impl<T: Default, E> Result<T, E> {
909909
}
910910
}
911911

912+
impl<T, E> Result<Option<T>, E> {
913+
/// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
914+
///
915+
/// `Ok(None)` will be mapped to `None`.
916+
/// `Ok(Some(_))` and `Err(_)` will be mapped to `Some(Ok(_))` and `Some(Err(_))`.
917+
///
918+
/// # Examples
919+
///
920+
/// ```
921+
/// #![feature(transpose_result)]
922+
///
923+
/// #[derive(Debug, Eq, PartialEq)]
924+
/// struct SomeErr;
925+
///
926+
/// let x: Result<Option<i32>, SomeErr> = Ok(Some(5));
927+
/// let y: Option<Result<i32, SomeErr>> = Some(Ok(5));
928+
/// assert_eq!(x.transpose(), y);
929+
/// ```
930+
#[inline]
931+
#[unstable(feature = "transpose_result", issue = "47338")]
932+
pub fn transpose(self) -> Option<Result<T, E>> {
933+
match self {
934+
Ok(Some(x)) => Some(Ok(x)),
935+
Ok(None) => None,
936+
Err(e) => Some(Err(e)),
937+
}
938+
}
939+
}
940+
912941
// This is a separate function to reduce the code size of the methods
913942
#[inline(never)]
914943
#[cold]

0 commit comments

Comments
 (0)