Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #47622

Merged
merged 23 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
176624f
add kbd style tag to main.css in rustdoc
hellow554 Dec 21, 2017
6e741df
moved colors of kbd tag into main.css
hellow554 Dec 22, 2017
c9ae249
Add transpose conversions for Option and Result
cramertj Jan 4, 2018
38e5d30
extended dt with kbd tags
hellow554 Jan 15, 2018
0e1ecbe
add Rust By Example to the bookshelf
QuietMisdreavus Jan 17, 2018
1b9c656
Add some edge cases to the documentation of `Path`
tbu- Jan 18, 2018
908aa38
Deprecate std::net::lookup_host
sfackler Jan 17, 2018
0c946c0
converted space to tab in css files
hellow554 Jan 18, 2018
005791b
add target/ to ignored tidy dirs
Manishearth Jan 18, 2018
9a4287d
Update CONTRIBUTING.md
walinga Jan 18, 2018
8d7f554
Give TargetOptions::linker a sane default value.
EdSchouten Jan 19, 2018
fdf444d
Update BTreeMap recommendation
arthurprs Jan 19, 2018
7ed00ca
Closure argument mismatch tweaks
estebank Jan 19, 2018
fe811eb
Rollup merge of #46938 - hellow554:rustdoc-kbd-style, r=GuillaumeGomez
GuillaumeGomez Jan 20, 2018
0e270fc
Rollup merge of #47193 - cramertj:result-opts, r=TimNN
GuillaumeGomez Jan 20, 2018
d3176ef
Rollup merge of #47508 - QuietMisdreavus:rbe-bookshelf, r=steveklabnik
GuillaumeGomez Jan 20, 2018
5381dfb
Rollup merge of #47510 - sfackler:deprecate-dns, r=alexcrichton
GuillaumeGomez Jan 20, 2018
b21499e
Rollup merge of #47532 - tbu-:pr_path_oddities, r=TimNN
GuillaumeGomez Jan 20, 2018
0f84ab4
Rollup merge of #47535 - Manishearth:ignore-target, r=kennytm
GuillaumeGomez Jan 20, 2018
ea65bad
Rollup merge of #47559 - walinga:pr-link-fix, r=kennytm
GuillaumeGomez Jan 20, 2018
40ba599
Rollup merge of #47568 - EdSchouten:cloudabi-linker, r=alexcrichton
GuillaumeGomez Jan 20, 2018
a9672c2
Rollup merge of #47573 - estebank:closures, r=nikomatsakis
GuillaumeGomez Jan 20, 2018
4074893
Rollup merge of #47578 - arthurprs:btree-doc, r=alexcrichton
GuillaumeGomez Jan 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ It's absolutely fine to have multiple build directories with different
[pull-requests]: #pull-requests

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

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

Please make pull requests against the `master` branch.
Expand Down
2 changes: 2 additions & 0 deletions src/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Rust provides a number of book-length sets of documentation, collectively
nicknamed 'The Rust Bookshelf.'

* [The Rust Programming Language][book] teaches you how to program in Rust.
* [Rust By Example][rbe] teaches you how to program in Rust using editable examples.
* [The Cargo Book][cargo-book] is a guide to Cargo, Rust's build tool and dependency manager.
* [The Unstable Book][unstable-book] has documentation for unstable features.
* [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust.
Expand All @@ -51,6 +52,7 @@ before this policy was put into place. That work is being tracked
[refchecklist]: https://github.com/rust-lang-nursery/reference/issues/9
[err]: error-index.html
[book]: book/index.html
[rbe]: rust-by-example/index.html
[nomicon]: nomicon/index.html
[unstable-book]: unstable-book/index.html
[rustdoc-book]: rustdoc/index.html
Expand Down
29 changes: 29 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,35 @@ impl<T: Default> Option<T> {
}
}

impl<T, E> Option<Result<T, E>> {
/// Transposes an `Option` of a `Result` into a `Result` of an `Option`.
///
/// `None` will be mapped to `Ok(None)`.
/// `Some(Ok(_))` and `Some(Err(_))` will be mapped to `Ok(Some(_))` and `Err(_)`.
///
/// # Examples
///
/// ```
/// #![feature(transpose_result)]
///
/// #[derive(Debug, Eq, PartialEq)]
/// struct SomeErr;
///
/// let x: Result<Option<i32>, SomeErr> = Ok(Some(5));
/// let y: Option<Result<i32, SomeErr>> = Some(Ok(5));
/// assert_eq!(x, y.transpose());
/// ```
#[inline]
#[unstable(feature = "transpose_result", issue = "47338")]
pub fn transpose(self) -> Result<Option<T>, E> {
match self {
Some(Ok(x)) => Ok(Some(x)),
Some(Err(e)) => Err(e),
None => Ok(None),
}
}
}

// This is a separate function to reduce the code size of .expect() itself.
#[inline(never)]
#[cold]
Expand Down
29 changes: 29 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,35 @@ impl<T: Default, E> Result<T, E> {
}
}

impl<T, E> Result<Option<T>, E> {
/// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
///
/// `Ok(None)` will be mapped to `None`.
/// `Ok(Some(_))` and `Err(_)` will be mapped to `Some(Ok(_))` and `Some(Err(_))`.
///
/// # Examples
///
/// ```
/// #![feature(transpose_result)]
///
/// #[derive(Debug, Eq, PartialEq)]
/// struct SomeErr;
///
/// let x: Result<Option<i32>, SomeErr> = Ok(Some(5));
/// let y: Option<Result<i32, SomeErr>> = Some(Ok(5));
/// assert_eq!(x.transpose(), y);
/// ```
#[inline]
#[unstable(feature = "transpose_result", issue = "47338")]
pub fn transpose(self) -> Option<Result<T, E>> {
match self {
Ok(Some(x)) => Some(Ok(x)),
Ok(None) => None,
Err(e) => Some(Err(e)),
}
}
}

// This is a separate function to reduce the code size of the methods
#[inline(never)]
#[cold]
Expand Down
Loading