Commit Graph

117 Commits

Author SHA1 Message Date
Tshepang Mbambo
6da64379ab "Basic usage" is redundant for there is just one example 2023-02-16 19:49:31 +02:00
Michael Howell
fa6c3a2d2a docs: update fragment for Result impls 2023-02-03 19:03:17 -07:00
Chris AtLee
e0fd37dcf7 Improve wording for Option and Result 2022-12-13 14:49:10 -05:00
bors
91931ec2fc Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-se
Change `is_some_and` to take by value

Consistent with other function-accepting `Option` methods.

Tracking issue: #93050

r? `@m-ou-se`
2022-10-02 12:48:15 +00:00
Cameron Steffen
4f12de0660 Change feature name to is_some_and 2022-10-01 11:45:52 -05:00
Cameron Steffen
2f83134e37 Change is_some_and to take by value 2022-10-01 11:45:52 -05:00
Marijn Schouten
ac310e6643
Update result.rs
Remove a FIXME whose code got moved away in https://github.com/rust-lang/rust/pull/62883.
2022-09-28 14:52:59 +02:00
onestacked
84666afb36 Constify Residual behind const_try 2022-09-23 20:17:31 +02:00
Yuki Okushi
ba31a9b505
Rollup merge of #100604 - dtolnay:okorerr, r=m-ou-se
Remove unstable Result::into_ok_or_err

Pending FCP: https://github.com/rust-lang/rust/issues/82223#issuecomment-1214920203

```@rustbot``` label +waiting-on-fcp
2022-08-26 09:51:44 +09:00
Chayim Refael Friedman
eb2fdd917e Add a warning about Option/Result::and() being eagerly evaluated
Copied from `or()`.
2022-08-23 16:15:09 +00:00
David Tolnay
83f081fc01
Remove unstable Result::into_ok_or_err 2022-08-17 17:20:42 -07:00
Nathan Stocks
7ba0be832a add same warning to Result::expect as Result::unwrap 2022-07-21 18:15:24 -06:00
Guillaume Gomez
53db831d62 Fix links in std/core documentation 2022-07-05 21:33:39 +02:00
Matthias Krüger
82beeabf54
Rollup merge of #96033 - yaahc:expect-elaboration, r=scottmcm
Add section on common message styles for Result::expect

Based on a question from https://github.com/rust-lang/project-error-handling/issues/50#issuecomment-1092339937

~~One thing I haven't decided on yet, should I duplicate this section on `Option::expect`, link to this section, or move it somewhere else and link to that location from both docs?~~: I ended up moving the section to `std::error` and referencing it from both `Result::expect` and `Option::expect`'s docs.

I think this section, when combined with the similar update I made on [`std::panic!`](https://doc.rust-lang.org/nightly/std/macro.panic.html#when-to-use-panic-vs-result) implies that we should possibly more aggressively encourage and support the "expect as precondition" style described in this section. The consensus among the libs team seems to be that panic should be used for bugs, not expected potential failure modes. The "expect as error message" style seems to align better with the panic for unrecoverable errors style where they're seen as normal errors where the only difference is a desire to kill the current execution unit (aka erlang style error handling). I'm wondering if we should be providing a panic hook similar to `human-panic` or more strongly recommending the "expect as precondition" style of expect message.
2022-05-26 20:59:40 +02:00
Jane Lusby
720e987ac0 update option and result references to expect message docs 2022-05-25 11:37:39 -07:00
Jane Lusby
7b5dce900d This is a pretty good start if you ask me 2022-05-06 15:03:25 -07:00
Scott McMurray
e094ee5f10 Add do yeet expressions to allow experimentation in nightly
Using an obviously-placeholder syntax.  An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point.

But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-30 17:40:27 -07:00
Jane Losare-Lusby
72898acdba spicy 2022-04-30 03:32:41 +00:00
Jane Lusby
00a315c515
Update library/core/src/result.rs
Co-authored-by: Emil Thorenfeldt <emt@magenta.dk>
2022-04-18 16:31:21 -07:00
Jane Lusby
eca7dd20d5
Update library/core/src/result.rs
Co-authored-by: Emil Thorenfeldt <emt@magenta.dk>
2022-04-18 16:31:13 -07:00
Jane Lusby
5d98acb19c update docs for option to crossreference to the result docs 2022-04-15 10:24:34 -07:00
Jane Lusby
80c362b92b add should_panic annotations 2022-04-14 13:22:24 -07:00
Jane Lusby
3d951b3d21 add necessary text attribute to code block of panic output 2022-04-14 11:40:27 -07:00
Jane Lusby
dfb37cb088 Add section on common message styles for Result::expect 2022-04-13 19:08:10 -07:00
Pietro Albini
181d28bb61
trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
David Tolnay
4246916619
Adjust feature names that disagree on const stabilization version 2022-03-31 12:34:48 -07:00
Deadbeef
1f3ee7f32e
Rename ~const Drop to ~const Destruct 2022-03-21 17:04:03 +11:00
Dylan DPC
6d66020594
Rollup merge of #94765 - m-ou-se:is-some-and, r=Dylan-DPC
Rename is_{some,ok,err}_with to is_{some,ok,err}_and.

This renames `is_{some,ok,err}_with` to `is_{some,ok,err}_and`. This was discussed on the [tracking issue](https://github.com/rust-lang/rust/issues/93050).
2022-03-11 03:32:04 +01:00
T-O-R-U-S
72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00
Matthias Krüger
c0259626b6
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
Make some `Clone` impls `const`

Tracking issue: #91805
`Clone::clone_from` and some impls (Option, Result) bounded on `~const Drop`.

```rust
// core::clone
impl const Clone for INTEGER
impl const Clone for FLOAT
impl const Clone for bool
impl const Clone for char
impl const Clone for !
impl<T: ?Sized> const Clone for *const T
impl<T: ?Sized> const Clone for *mut T
impl<T: ?Sized> const Clone for &T

// core::option
impl<T> const Clone for Option<T>
where
    T: ~const Clone + ~const Drop

// core::result
impl<T, E> const Clone for Result<T, E>
where
    T: ~const Clone + ~const Drop,
    E: ~const Clone + ~const Drop,

// core::convert
impl const Clone for Infallible

// core::ptr
impl<T: ?Sized> const Clone for NonNull<T>
impl<T: ?Sized> const Clone for Unique<T>
```
2022-03-09 23:14:09 +01:00
Mara Bos
7c7411fb5d Rename is_{some,ok,err}_with to is_{some,ok,err}_and. 2022-03-09 11:20:36 +01:00
Matthias Krüger
e22331ce02
Rollup merge of #92385 - clarfonthey:const_option, r=fee1-dead
Add Result::{ok, err, and, or, unwrap_or} as const

Already opened tracking issue #92384.

I don't think that this should actually cause any issues as long as the constness is unstable, but we may want to double-check that this doesn't get interpreted as a weird `Drop` bound even for non-const usages.
2022-03-08 11:04:50 +01:00
cyqsimon
f6f93fd7ba
Add note on Windows path behaviour 2022-02-12 12:52:42 +08:00
cyqsimon
adfac00f45
Result::and_then: show type conversion 2022-02-12 12:19:03 +08:00
cyqsimon
7eaecc6508
Result::and_then: improve basic example 2022-02-12 12:12:11 +08:00
cyqsimon
942eaa7ffc
Add negative example for Result::and_then 2022-02-11 09:57:19 +08:00
cyqsimon
bd421e2880
More practical examples for Result::and_then 2022-02-10 17:59:46 +08:00
Scott McMurray
413945ecc5 Change ResultShunt to be generic over Try
Just a refactor (and rename) for now, so it's not `Result`-specific.

This could be used for a future `Iterator::try_collect`, or similar, but anything like that is left for a future PR.
2022-02-07 12:57:25 -08:00
ltdk
19645ac05a Add Result::{ok, err, and, or, unwrap_or} as const 2022-01-29 18:37:55 -05:00
Mara Bos
5fee3e7a9c Fix is_some_with tests. 2022-01-19 00:12:35 +01:00
Mara Bos
45dee47fec Improve is_err_with example. 2022-01-18 22:53:43 +01:00
Mara Bos
148234ff73 Add is_some_with tracking issue number. 2022-01-18 22:18:16 +01:00
Mara Bos
aaebae973f Add Result::{is_ok_with, is_err_with}. 2022-01-18 22:17:44 +01:00
Lucas Kent
08829853d3 eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
Matthias Krüger
051d591edf
Rollup merge of #92483 - ksqsf:master, r=dtolnay
Stabilize `result_cloned` and `result_copied`

Tracking issue: #63168

The FCP is now completed.
2022-01-05 15:05:47 +01:00
ksqsf
1c547f422a Stabilize result_cloned and result_copied 2022-01-04 13:23:32 +08:00
David Tolnay
7dec41a236
Move contains method of Option and Result lower in docs 2022-01-03 10:46:15 -08:00
David Tolnay
b7a0ab18f6
Consolidate impl Result<&mut T, E> 2021-12-30 10:31:26 -08:00
David Tolnay
e63e2680da
Consolidate impl Result<&T, E> 2021-12-30 10:30:28 -08:00
David Tolnay
b2df61fa9f
Move Result::into_err 2021-12-30 10:28:54 -08:00