From 98425c1d83b6e3be1abc254405d7a1f5c22ed86a Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Mon, 30 Aug 2021 18:13:52 -0500 Subject: [PATCH 1/3] allow setting the route name --- core/codegen/src/attribute/route/mod.rs | 9 ++++++++- core/codegen/src/attribute/route/parse.rs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/codegen/src/attribute/route/mod.rs b/core/codegen/src/attribute/route/mod.rs index b162ff5af2..baecf6da0e 100644 --- a/core/codegen/src/attribute/route/mod.rs +++ b/core/codegen/src/attribute/route/mod.rs @@ -330,6 +330,13 @@ fn codegen_route(route: Route) -> Result { let rank = Optional(route.attr.rank); let format = Optional(route.attr.format.as_ref()); + let route_name = match &route.attr.name { + Some(name) => quote! { #name }, + None => { + quote! { stringify!(#handler_fn_name) } + } + }; + Ok(quote! { #handler_fn @@ -357,7 +364,7 @@ fn codegen_route(route: Route) -> Result { } #_route::StaticInfo { - name: stringify!(#handler_fn_name), + name: #route_name, method: #method, uri: #uri, handler: monomorphized_function, diff --git a/core/codegen/src/attribute/route/parse.rs b/core/codegen/src/attribute/route/parse.rs index 02ceaac6bc..00608f9d94 100644 --- a/core/codegen/src/attribute/route/parse.rs +++ b/core/codegen/src/attribute/route/parse.rs @@ -47,6 +47,7 @@ pub struct Attribute { pub data: Option>, pub format: Option, pub rank: Option, + pub name: Option, } /// The parsed `#[method(..)]` (e.g, `get`, `put`, etc.) attribute. @@ -57,6 +58,7 @@ pub struct MethodAttribute { pub data: Option>, pub format: Option, pub rank: Option, + pub name: Option, } #[derive(Debug)] From 10c981960864ef7a788a292c9662d3ea279da828 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Mon, 30 Aug 2021 19:27:34 -0500 Subject: [PATCH 2/3] make Router public --- core/lib/src/lib.rs | 1 + core/lib/src/router/mod.rs | 1 + core/lib/src/router/router.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/lib/src/lib.rs b/core/lib/src/lib.rs index 3fe85b2c05..30e0ef2401 100644 --- a/core/lib/src/lib.rs +++ b/core/lib/src/lib.rs @@ -159,6 +159,7 @@ mod phase; #[doc(inline)] pub use crate::config::Config; #[doc(inline)] pub use crate::catcher::Catcher; #[doc(inline)] pub use crate::route::Route; +#[doc(inline)] pub use crate::router::Router; #[doc(hidden)] pub use either::Either; #[doc(inline)] pub use phase::{Phase, Build, Ignite, Orbit}; #[doc(inline)] pub use error::Error; diff --git a/core/lib/src/router/mod.rs b/core/lib/src/router/mod.rs index dc1a662187..a0c01e32e9 100644 --- a/core/lib/src/router/mod.rs +++ b/core/lib/src/router/mod.rs @@ -3,5 +3,6 @@ mod router; mod collider; +pub use router::Router; pub(crate) use router::*; pub(crate) use collider::*; diff --git a/core/lib/src/router/router.rs b/core/lib/src/router/router.rs index 08408a4fca..2da44536c6 100644 --- a/core/lib/src/router/router.rs +++ b/core/lib/src/router/router.rs @@ -7,7 +7,7 @@ use crate::{Route, Catcher}; use crate::router::Collide; #[derive(Debug, Default)] -pub(crate) struct Router { +pub struct Router { routes: HashMap>, catchers: HashMap, Vec>, } From 410b3f872313a881007c88506888a7dd59a8c43c Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Mon, 30 Aug 2021 20:48:17 -0500 Subject: [PATCH 3/3] add to Attribute --- core/codegen/src/attribute/route/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/codegen/src/attribute/route/mod.rs b/core/codegen/src/attribute/route/mod.rs index baecf6da0e..247ab1847d 100644 --- a/core/codegen/src/attribute/route/mod.rs +++ b/core/codegen/src/attribute/route/mod.rs @@ -422,6 +422,7 @@ fn incomplete_route( data: method_attribute.data, format: method_attribute.format, rank: method_attribute.rank, + name: method_attribute.name, }; codegen_route(Route::from(attribute, function)?)