From 71d11644a71b243f8f4506b715db4f7c5dddbae1 Mon Sep 17 00:00:00 2001 From: Andrey Torsunov Date: Sun, 26 Jan 2020 01:22:40 +0300 Subject: [PATCH] Add ability to name a handler function as 'config' (#1290) * eliminate handler naming restrictions #1277 * Update actix-web-codegen/CHANGES.md Co-authored-by: Yuki Okushi --- actix-web-codegen/CHANGES.md | 4 ++++ actix-web-codegen/src/route.rs | 6 +++--- actix-web-codegen/tests/test_macro.rs | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/actix-web-codegen/CHANGES.md b/actix-web-codegen/CHANGES.md index de676f688..95696abd3 100644 --- a/actix-web-codegen/CHANGES.md +++ b/actix-web-codegen/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.2.NEXT] - 2020-xx-xx + +* Allow the handler function to be named as `config` #1290 + ## [0.2.0] - 2019-12-13 * Generate code for actix-web 2.0 diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index 16d3e8157..d48198484 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -195,15 +195,15 @@ impl Route { pub struct #name; impl actix_web::dev::HttpServiceFactory for #name { - fn register(self, config: &mut actix_web::dev::AppService) { + fn register(self, __config: &mut actix_web::dev::AppService) { #ast - let resource = actix_web::Resource::new(#path) + let __resource = actix_web::Resource::new(#path) .name(#resource_name) .guard(actix_web::guard::#guard()) #(.guard(actix_web::guard::fn_guard(#extra_guards)))* .#resource_type(#name); - actix_web::dev::HttpServiceFactory::register(resource, config) + actix_web::dev::HttpServiceFactory::register(__resource, __config) } } }; diff --git a/actix-web-codegen/tests/test_macro.rs b/actix-web-codegen/tests/test_macro.rs index 4ac1a8023..ffb50c11e 100644 --- a/actix-web-codegen/tests/test_macro.rs +++ b/actix-web-codegen/tests/test_macro.rs @@ -2,6 +2,12 @@ use actix_web::{http, test, web::Path, App, HttpResponse, Responder}; use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace}; use futures::{future, Future}; +// Make sure that we can name function as 'config' +#[get("/config")] +async fn config() -> impl Responder { + HttpResponse::Ok() +} + #[get("/test")] async fn test_handler() -> impl Responder { HttpResponse::Ok()