mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-20 12:45:41 +02:00
Remove implementation of Responder for (). Fixes #1108.
Rationale: - In Rust, one can omit a semicolon after a function's final expression to make its value the function's return value. It's common for people to include a semicolon after the last expression by mistake - common enough that the Rust compiler suggests removing the semicolon when there's a type mismatch between the function's signature and body. By implementing Responder for (), Actix makes this common mistake a silent error in handler functions. - Functions returning an empty body should return HTTP status 204 ("No Content"), so the current Responder impl for (), which returns status 200 ("OK"), is not really what one wants anyway. - It's not much of a burden to ask handlers to explicitly return `HttpResponse::Ok()` if that is what they want; all the examples in the documentation do this already.
This commit is contained in:
@@ -146,7 +146,7 @@ where
|
||||
/// match guards for route selection.
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::{web, guard, App, HttpResponse};
|
||||
/// use actix_web::{web, guard, App};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = App::new().service(
|
||||
@@ -156,9 +156,9 @@ where
|
||||
/// .route(web::delete().to(delete_handler))
|
||||
/// );
|
||||
/// }
|
||||
/// # async fn get_handler() -> impl actix_web::Responder { HttpResponse::Ok() }
|
||||
/// # async fn post_handler() -> impl actix_web::Responder { HttpResponse::Ok() }
|
||||
/// # async fn delete_handler() -> impl actix_web::Responder { HttpResponse::Ok() }
|
||||
/// # async fn get_handler() -> impl actix_web::Responder { actix_web::HttpResponse::Ok() }
|
||||
/// # async fn post_handler() -> impl actix_web::Responder { actix_web::HttpResponse::Ok() }
|
||||
/// # async fn delete_handler() -> impl actix_web::Responder { actix_web::HttpResponse::Ok() }
|
||||
/// ```
|
||||
pub fn route(mut self, route: Route) -> Self {
|
||||
self.routes.push(route);
|
||||
|
Reference in New Issue
Block a user