chore: remove Option<()> impl

This commit is contained in:
Rob Ede 2025-02-09 01:44:34 +00:00
parent e1b204bb2a
commit a2a8edb3a5
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 9 additions and 15 deletions

View File

@ -3,9 +3,9 @@
## Unreleased ## Unreleased
- 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.
- Implemented `Responder` for `Result<(), E: Into<Error>>`. Returning `Ok(())` responds with HTTP 204 No Content.
- 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.
- Implemented responder for `Option<()>` and `Result<(), E: Error> to respond with `204 No Content`
## 4.9.0 ## 4.9.0

View File

@ -116,17 +116,6 @@ impl<R: Responder> Responder for Option<R> {
} }
} }
//Note see https://github.com/actix/actix-web/issues/1108 on why Responder is not implemented for ()
impl Responder for Option<()> {
type Body = BoxBody;
fn respond_to(self, _req: &HttpRequest) -> HttpResponse {
match self {
Some(()) => HttpResponse::NoContent().finish(),
None => HttpResponse::NotFound().finish(),
}
}
}
impl<R, E> Responder for Result<R, E> impl<R, E> Responder for Result<R, E>
where where
R: Responder, R: Responder,
@ -142,14 +131,19 @@ where
} }
} }
//Note see https://github.com/actix/actix-web/issues/1108 on why Responder is not implemented for () // Note: see https://github.com/actix/actix-web/issues/1108 for reasoning why Responder is not
impl<E: Into<Error>> Responder for Result<(), E> { // 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; type Body = BoxBody;
fn respond_to(self, _req: &HttpRequest) -> HttpResponse { fn respond_to(self, _req: &HttpRequest) -> HttpResponse {
match self { match self {
Ok(()) => HttpResponse::new(StatusCode::NO_CONTENT), Ok(()) => HttpResponse::new(StatusCode::NO_CONTENT),
Err(e) => HttpResponse::from_error(e.into()), Err(err) => HttpResponse::from_error(err.into()),
} }
} }
} }