@@ -270,7 +270,7 @@ will be routed as follows:
270
270
You'll also find a route's rank logged in brackets during application launch:
271
271
` GET /user/<id> [3] (user_str) ` .
272
272
273
- Forwards can be _ caught_ by using a ` Result ` or ` Option ` type. For example, if
273
+ Forwards can be _ caught_ by using a ` Option ` type. For example, if
274
274
the type of ` id ` in the ` user ` function was ` Result<usize, &str> ` , then ` user `
275
275
would never forward. An ` Ok ` variant would indicate that ` <id> ` was a valid
276
276
` usize ` , while an ` Err ` would indicate that ` <id> ` was not a ` usize ` . The
@@ -279,7 +279,7 @@ would never forward. An `Ok` variant would indicate that `<id>` was a valid
279
279
! tip: It's not just forwards that can be caught!
280
280
281
281
In general, when any guard fails for any reason, including parameter guards,
282
- you can use an ` Option ` or ` Result ` type in its place to catch the error.
282
+ you can use a ` Result ` type in its place to catch the error.
283
283
284
284
By the way, if you were to omit the ` rank ` parameter in the ` user_str ` or
285
285
` user_int ` routes, Rocket would emit an error and abort launch, indicating that
@@ -511,8 +511,7 @@ it always succeeds. The user is redirected to a log in page.
511
511
### Fallible Guards
512
512
513
513
A failing or forwarding guard can be "caught" in handler, preventing it from
514
- failing or forwarding, via the ` Option<T> ` and ` Result<T, E> ` guards. When a
515
- guard ` T ` fails or forwards, ` Option<T> ` will be ` None ` . If a guard ` T ` fails
514
+ failing or forwarding, via ` Result<T, E> ` guards. If a guard ` T ` fails
516
515
with error ` E ` , ` Result<T, E> ` will be ` Err(E) ` .
517
516
518
517
As an example, for the ` User ` guard above, instead of allowing the guard to
@@ -538,7 +537,7 @@ fn admin_panel_user(user: Option<User>) -> Result<&'static str, Redirect> {
538
537
}
539
538
```
540
539
541
- If the ` User ` guard forwards or fails , the ` Option ` will be ` None ` . If it
540
+ If the ` User ` guard forwards, the ` Option ` will be ` None ` . If it
542
541
succeeds, it will be ` Some(User) ` .
543
542
544
543
For guards that may fail (and not just forward), the ` Result<T, E> ` guard allows
@@ -898,14 +897,14 @@ If a `POST /todo` request arrives, the form data will automatically be parsed
898
897
into the ` Task ` structure. If the data that arrives isn't of the correct
899
898
Content-Type, the request is forwarded. If the data doesn't parse or is simply
900
899
invalid, a customizable error is returned. As before, a forward or error can
901
- be caught by using the ` Option ` and ` Result ` types:
900
+ be caught by using the ` Result ` types:
902
901
903
902
``` rust
904
- # use rocket :: {post, form :: Form };
903
+ # use rocket :: {post, form :: { Form , Errors } };
905
904
# type Task <'r > = & 'r str ;
906
905
907
906
#[post(" /todo" , data = " <task>" )]
908
- fn new (task : Option <Form <Task <'_ >>>) { /* .. */ }
907
+ fn new (task : Result <Form <Task <'_ >>, Errors <' _ >>) { /* .. */ }
909
908
```
910
909
911
910
### Multipart
0 commit comments