diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index cee14dc4b..edbdc6982 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -2,6 +2,7 @@ ## Unreleased +- Implement `Responder` for `Result<(), E: Into>`. 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. diff --git a/actix-web/src/response/responder.rs b/actix-web/src/response/responder.rs index 90d8f6e52..82bc38d6b 100644 --- a/actix-web/src/response/responder.rs +++ b/actix-web/src/response/responder.rs @@ -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 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(err) => HttpResponse::from_error(err.into()), + } + } +} + impl Responder for (R, StatusCode) { type Body = R::Body;