Commit graph

360 commits

Author SHA1 Message Date
Lzu Tao
e8f3a9ffbe add Result::map_or 2019-11-12 03:22:04 +00:00
bors
5f42f3e108 Auto merge of #63166 - ksqsf:master, r=alexcrichton
Add Result::cloned{,_err} and Result::copied{,_err}

This is a little nice addition to `Result`.

1. I'm not sure how useful are `cloned_err` and `copied_err`, but for the sake of completeness they are here.
2. Naming is similar to `map`/`map_err`. I thought about naming `cloned` as `cloned_ok` and add another method called `cloned` that clones both Ok and Err, but `cloned_ok` should be more prevalent than `cloned_both`.
2019-09-04 07:47:08 +00:00
ksqsf
61e5286635 Remove Err variants of cloned and copied 2019-08-02 13:58:55 +08:00
ksqsf
9733f0d163 Fix doc tests 2019-08-01 19:18:03 +08:00
ksqsf
4b2f598986 Revert "cloned/copied"
This reverts commit 6c13081762.
2019-08-01 13:38:23 +08:00
ksqsf
6c13081762 Rename {copied,cloned} to {copied,cloned}_ok, and add {copied,cloned} to copy/clone both Ok and Err 2019-08-01 02:35:14 +08:00
ksqsf
5a36b0dba1 Make these methods public 2019-08-01 01:09:07 +08:00
ksqsf
c784720f3a Fix issue and impl 2019-08-01 00:55:36 +08:00
ksqsf
a0ab5a3651 Add Result::cloned{,_err} and Result::copied{,_err} 2019-08-01 00:26:47 +08:00
Tim Vermeulen
2e41ba8742 Use internal iteration in the Sum and Product impls of Result and Option 2019-07-29 02:40:50 +02:00
Stargateur
3334802c83 Refactoring use commun code between option, result and accum 2019-07-27 02:17:56 +02:00
Yuki Okushi
f2a97210b2 Use DerefMut 2019-07-18 15:18:41 +09:00
Brad Gibson
d1aca3aea5 renamed inner_deref feature's deref*() methods as_deref*() as per discussion https://github.com/rust-lang/rust/issues/50264 2019-07-18 15:17:30 +09:00
bors
d56128d291 Auto merge of #62596 - cuviper:expect_none, r=rkruppe
Add Option::expect_none(msg) and unwrap_none()

These are `Option` analogues to `Result::expect_err` and `unwrap_err`.
2019-07-17 08:29:02 +00:00
Mazdak Farrokhzad
f169b15e1d
Rollup merge of #62431 - czipperz:add-messages-to-must-use-is_-methods, r=scottmcm
Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*`

r? @RalfJung
2019-07-12 22:46:41 +02:00
Josh Stone
955979ab28 Make cold unwraps take &dyn Debug 2019-07-11 12:40:38 -07:00
Simon Ochsenreither
6f76da494b Implement Option::contains, Result::contains and Result::contains_err
This increases consistency with other common data structures.
2019-07-07 16:50:44 +02:00
Chris Gregory
145385e7c3 Add messages to Option and Result must_use for is_* 2019-07-05 20:57:25 -07:00
Mara Bos
67fd99589a Implement Clone::clone_from for Result. 2019-06-01 09:14:59 +02:00
Mazdak Farrokhzad
dbfbadeac4 libcore: deny more... 2019-04-19 01:37:12 +02:00
Taiki Endo
360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Alex Gaynor
ce5d69480a Add must_use annotations to Result::is_ok and is_err 2019-04-08 12:58:09 -04:00
Felix S Klock II
0e83e96852
add missing braces
add missing braces analogous to those suggested by killercup
2019-03-25 11:50:11 +01:00
Felix S. Klock II
d5a61c0be2 Expand impl FromIterator for Result doc to include examples of Err and early termination. 2019-03-22 12:44:08 +01:00
Chris Gregory
9a61580d40 Option and Result: Add references to documentation of as_ref and as_mut 2019-03-15 16:42:10 -04:00
Chris Gregory
6b88c90504 impl FromIterator for Result: Use assert_eq! instead of assert! 2019-03-11 21:04:34 -04:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad
6d7a4a6e4c stabilize transpose_result in 1.33 2019-01-13 06:15:44 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Scott McMurray
0a3bd9b6ab Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
kennytm
4f62077a2c
Rollup merge of #53777 - ivanbakel:result_map_or_else, r=alexcrichton
Implemented map_or_else for Result<T, E>

Fulfills #53268
The example is ripped from `Option::map_or_else`, with the types corrected.
2018-09-12 12:17:25 +08:00
Guillaume Gomez
c1ad1b0338 Fix invalid urls 2018-09-06 23:32:30 +02:00
Isaac van Bakel
79408c3f32 Added feature attribute to example code in map_or_else doc 2018-08-30 00:51:09 +01:00
Isaac van Bakel
6ff4f7946f Corrected type variable output T -> U in Result::map_or_else 2018-08-29 22:55:21 +01:00
Isaac van Bakel
3eda9058cf Corrected feature status of Result::map_or_else
map_or_else is now correctly labelled unstable and points to the
tracking issue on rust-lang/rust
2018-08-29 22:51:54 +01:00
Isaac van Bakel
71b16d8350 Corrected bad typing in Result::map_or_else doc
The error value now includes the type of the success.
The success value now includes the type of the error.
2018-08-29 22:15:17 +01:00
Isaac van Bakel
5eb679105f Corrected feature name for map_or_else 2018-08-29 13:08:52 +01:00
Isaac van Bakel
b8c60302e7 Implemented map_or_else for Result<T, E> 2018-08-29 02:37:57 +01:00
M Farkas-Dyck
b78201aee5 inline some short functions 2018-08-09 01:27:48 -08:00
Brad Gibson
56016cb1e0 resolved upstream merge conflicts 2018-07-29 22:13:12 -07:00
Manish Goregaokar
1abed9cebf Add explanation for #[must_use] on Result 2018-05-07 10:26:28 -07:00
Brad Gibson
2bf9fbc8d6 separated inner_deref Result impls 2018-04-27 06:36:37 -07:00
Brad Gibson
527e84f300 cleaned up #[unstable] attributes 2018-04-26 20:41:10 -07:00
Brad Gibson
6c7ea4ca9b refactored to implement without trait 2018-04-26 20:02:32 -07:00
Brad Gibson
4c2e3144a9 added DerefOption and DerefResult + tests to std 2018-04-26 18:14:23 -07:00
Ulrik Sverdrup
c7c23fe948 core: Update stability attributes for FusedIterator 2018-03-03 14:23:05 +01:00
Ulrik Sverdrup
bc651cac8d core: Stabilize FusedIterator
FusedIterator is a marker trait that promises that the implementing
iterator continues to return `None` from `.next()` once it has returned
`None` once (and/or `.next_back()`, if implemented).

The effects of FusedIterator are already widely available through
`.fuse()`, but with stable `FusedIterator`, stable Rust users can
implement this trait for their iterators when appropriate.
2018-03-03 14:14:03 +01:00
Taylor Cramer
c9ae249265 Add transpose conversions for Option and Result
These impls are useful when working with combinator
methods that expect an option or a result, but you
have a Result<Option<T>, E> instead of an Option<Result<T, E>>
or vice versa.
2018-01-10 17:42:47 -08:00
Guillaume Gomez
0b47f02267 Rollup merge of #46548 - jonathanstrong:master, r=dtolnay
Recommends lazily evaluated alternatives for `Option::or` and `Result::or`

Adds language to docs for `Option` and `Result` recommending the use of lazily evaluated alternatives when appropriate. These comments are intended to echo a [clippy lint] on the same topic. The [reddit discussion] may also be of interest.

[clippy lint]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#or_fun_call
[reddit discussion]: https://www.reddit.com/r/rust/comments/7hutqn/perils_of_optionor_and_resultor/
2017-12-07 23:59:04 +01:00
Jonathan Strong
5847d0babd adds links to methods, removes trailing whitespace 2017-12-07 12:19:24 -05:00