You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rewrite try to be written in terms of the Try trait
This rewrites the section to say that it uses the `Try` trait. I felt it
was a bit too awkward to avoid it (since it is unstable).
This keeps an explicit list of the types that the `Try` trait is
implemented for, and adds the missing types (like `ControlFlow`).
The intent is that when `Try` is stabilized that the desuggaring note
moves to a normative rule, the `expr.try.restricted-types` rule is
removed (and instead direct the user to the standard library
documentation).
I'm still holding out hope that they change the terminology, since I
think the current choice is going to be confusing.
This has a hack to allow `feature(try_trait_v2)` by abusing the style
checker by adding some spaces. I really wanted to keep this example
tested to ensure that it is kept up-to-date. However, I may regret this
in the future.
Fixes#1927
The try propagation operator (`?`) unwraps valid values or returns erroneous values, propagating them to the calling function.
201
+
The try propagation expression uses the value of the inner expression and the [`Try`][core::ops::Try] trait to decide whether to produce a value, and if so, what value to produce, or whether to return a value to the caller, and if so, what value to return.
202
202
203
203
> [!EXAMPLE]
204
204
> The following examples illustrate some basic uses of the try propagation expression.
205
205
>
206
206
> ```rust
207
207
> # usestd::num::ParseIntError;
208
208
> fntry_to_parse() ->Result<i32, ParseIntError> {
209
-
> letx:i32="123".parse()?; //x = 123
210
-
> lety:i32="24a".parse()?; //returns an Err() immediately
209
+
> letx:i32="123".parse()?; //`x` is `123`.
210
+
> lety:i32="24a".parse()?; //Returns an `Err()` immediately.
211
211
> Ok(x+y) // Doesn't run.
212
212
> }
213
213
>
@@ -269,32 +269,48 @@ The try propagation operator (`?`) unwraps valid values or returns erroneous val
269
269
> # }
270
270
> ```
271
271
272
+
> [!NOTE]
273
+
> The [`core::ops::Try`] traitiscurrentlyunstable, andthuscannotbeimplementedforusertypeswithoutusingthenightlyreleasechannel.
0 commit comments