mirror of
https://github.com/fafhrd91/actix-web
synced 2025-02-22 20:13:17 +01:00
implement Responder for Result<(), E: Error> (#3560)
* implement Responder for Option<()> and Result<(), E: Error> * chore: remove Option<()> impl * chore: fix changelog --------- Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
66e2afe306
commit
a4eaa7f0bb
@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Implement `Responder` for `Result<(), E: Into<Error>>`. Returning `Ok(())` responds with HTTP 204 No Content.
|
||||
- On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use.
|
||||
- Update `brotli` dependency to `7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
|
@ -131,6 +131,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// Note: see https://github.com/actix/actix-web/issues/1108 for reasoning why Responder is not
|
||||
// implemented for `()`, and https://github.com/actix/actix-web/pull/3560 for discussion about this
|
||||
// impl and the decision not to include a similar one for `Option<()>`.
|
||||
impl<E> Responder for Result<(), E>
|
||||
where
|
||||
E: Into<Error>,
|
||||
{
|
||||
type Body = BoxBody;
|
||||
|
||||
fn respond_to(self, _req: &HttpRequest) -> HttpResponse {
|
||||
match self {
|
||||
Ok(()) => HttpResponse::new(StatusCode::NO_CONTENT),
|
||||
Err(err) => HttpResponse::from_error(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Responder> Responder for (R, StatusCode) {
|
||||
type Body = R::Body;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user