1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-02-22 12:13:16 +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:
Akos Vandra-Meyer 2025-02-09 04:01:39 +01:00 committed by GitHub
parent 66e2afe306
commit a4eaa7f0bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -2,6 +2,7 @@
## Unreleased ## 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. - 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`. - Update `brotli` dependency to `7`.
- Minimum supported Rust version (MSRV) is now 1.75. - Minimum supported Rust version (MSRV) is now 1.75.

View File

@ -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) { impl<R: Responder> Responder for (R, StatusCode) {
type Body = R::Body; type Body = R::Body;