mirror of
https://github.com/rwf2/Rocket.git
synced 2025-02-20 23:52:02 +00:00
Update guide to reflect the removal of specialization in impl Responder for Result
.
`Result<T, E>` only implements `Responder` if both `T` and `E` implement `Responder`.
This commit is contained in:
parent
0c5e184299
commit
a2fa4296a0
@ -237,15 +237,15 @@ async fn files(file: PathBuf) -> Option<NamedFile> {
|
||||
|
||||
### `Result`
|
||||
|
||||
`Result` is a special kind of wrapping responder: its functionality depends on
|
||||
whether the error type `E` implements `Responder`.
|
||||
`Result` is another _wrapping_ responder: a `Result<T, E>` can only be returned
|
||||
when `T` implements `Responder` and `E` implements `Responder`.
|
||||
|
||||
When the error type `E` implements `Responder`, the wrapped `Responder` in `Ok`
|
||||
or `Err`, whichever it might be, is used to respond to the client. This means
|
||||
that the responder can be chosen dynamically at run-time, and two different
|
||||
kinds of responses can be used depending on the circumstances. Revisiting our
|
||||
file server, for instance, we might wish to provide more feedback to the user
|
||||
when a file isn't found. We might do this as follows:
|
||||
The wrapped `Responder` in `Ok` or `Err`, whichever it might be, is used to
|
||||
respond to the client. This means that the responder can be chosen dynamically
|
||||
at run-time, and two different kinds of responses can be used depending on the
|
||||
circumstances. Revisiting our file server, for instance, we might wish to
|
||||
provide more feedback to the user when a file isn't found. We might do this as
|
||||
follows:
|
||||
|
||||
```rust
|
||||
# #[macro_use] extern crate rocket;
|
||||
@ -262,10 +262,6 @@ async fn files(file: PathBuf) -> Result<NamedFile, NotFound<String>> {
|
||||
}
|
||||
```
|
||||
|
||||
If the error type `E` _does not_ implement `Responder`, then the error is simply
|
||||
logged to the console, using its `Debug` implementation, and a `500` error is
|
||||
returned to the client.
|
||||
|
||||
## Rocket Responders
|
||||
|
||||
Some of Rocket's best features are implemented through responders. You can find
|
||||
|
Loading…
Reference in New Issue
Block a user