From c368a71320e69fb4bdee625d4e27281c1627a5b5 Mon Sep 17 00:00:00 2001 From: Benjamin Fry Date: Fri, 23 Jun 2017 11:36:04 -0700 Subject: [PATCH] add static route info to Route --- codegen/src/decorators/route.rs | 2 ++ lib/src/codegen.rs | 1 + lib/src/router/route.rs | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/codegen/src/decorators/route.rs b/codegen/src/decorators/route.rs index 37256036..97a4de71 100644 --- a/codegen/src/decorators/route.rs +++ b/codegen/src/decorators/route.rs @@ -269,6 +269,7 @@ fn generic_route_decorator(known_method: Option>, // function as its handler. A proper Rocket route will be created from this. let struct_name = user_fn_name.prepend(ROUTE_STRUCT_PREFIX); let (path, method, media_type, rank) = route.explode(ecx); + let handler_name = user_fn_name.to_string(); let static_route_info_item = quote_item!(ecx, /// Rocket code generated static route information structure. #[allow(non_upper_case_globals)] @@ -277,6 +278,7 @@ fn generic_route_decorator(known_method: Option>, method: $method, path: $path, handler: $route_fn_name, + handler_name: $handler_name, format: $media_type, rank: $rank, }; diff --git a/lib/src/codegen.rs b/lib/src/codegen.rs index 7741584a..f62cba3b 100644 --- a/lib/src/codegen.rs +++ b/lib/src/codegen.rs @@ -6,6 +6,7 @@ pub struct StaticRouteInfo { pub path: &'static str, pub format: Option, pub handler: Handler, + pub handler_name: &'static str, pub rank: Option, } diff --git a/lib/src/router/route.rs b/lib/src/router/route.rs index 9ba6bbcb..1e5acd10 100644 --- a/lib/src/router/route.rs +++ b/lib/src/router/route.rs @@ -23,6 +23,9 @@ pub struct Route { pub rank: isize, /// The media type this route matches against, if any. pub format: Option, + /// Static route information generated by codegen + #[doc(hidden)] + pub route_info: Option<&'static StaticRouteInfo>, } #[inline(always)] @@ -86,6 +89,7 @@ impl Route { base: URI::from("/"), uri: uri, format: None, + route_info: None, } } @@ -116,6 +120,7 @@ impl Route { uri: URI::from(uri.as_ref().to_string()), rank: rank, format: None, + route_info: None, } } @@ -227,6 +232,7 @@ impl Clone for Route { base: self.base.clone(), uri: self.uri.clone(), format: self.format.clone(), + route_info: self.route_info.clone(), } } } @@ -254,10 +260,11 @@ impl fmt::Debug for Route { } #[doc(hidden)] -impl<'a> From<&'a StaticRouteInfo> for Route { +impl<'a> From<&'a StaticRouteInfo> for Route where 'a: 'static { fn from(info: &'a StaticRouteInfo) -> Route { let mut route = Route::new(info.method, info.path, info.handler); route.format = info.format.clone(); + route.route_info = Some(info); if let Some(rank) = info.rank { route.rank = rank; }