From a2a8edb3a5159002a737cba03fd7965a0b189ac8 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 9 Feb 2025 01:44:34 +0000 Subject: [PATCH] chore: remove Option<()> impl --- actix-web/CHANGES.md | 2 +- actix-web/src/response/responder.rs | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 25a9b65ff..47f42b85a 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -3,9 +3,9 @@ ## Unreleased - 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>`. Returning `Ok(())` responds with HTTP 204 No Content. - Update `brotli` dependency to `7`. - 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 diff --git a/actix-web/src/response/responder.rs b/actix-web/src/response/responder.rs index 03f6cd087..82bc38d6b 100644 --- a/actix-web/src/response/responder.rs +++ b/actix-web/src/response/responder.rs @@ -116,17 +116,6 @@ impl Responder for Option { } } -//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 Responder for Result where R: Responder, @@ -142,14 +131,19 @@ where } } -//Note see https://github.com/actix/actix-web/issues/1108 on why Responder is not implemented for () -impl> Responder for Result<(), E> { +// 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 Responder for Result<(), E> +where + E: Into, +{ type Body = BoxBody; fn respond_to(self, _req: &HttpRequest) -> HttpResponse { match self { Ok(()) => HttpResponse::new(StatusCode::NO_CONTENT), - Err(e) => HttpResponse::from_error(e.into()), + Err(err) => HttpResponse::from_error(err.into()), } } }