mirror of https://github.com/rwf2/Rocket.git
add static route info to Route
This commit is contained in:
parent
6021609ee3
commit
c368a71320
|
@ -269,6 +269,7 @@ fn generic_route_decorator(known_method: Option<Spanned<Method>>,
|
||||||
// function as its handler. A proper Rocket route will be created from this.
|
// function as its handler. A proper Rocket route will be created from this.
|
||||||
let struct_name = user_fn_name.prepend(ROUTE_STRUCT_PREFIX);
|
let struct_name = user_fn_name.prepend(ROUTE_STRUCT_PREFIX);
|
||||||
let (path, method, media_type, rank) = route.explode(ecx);
|
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,
|
let static_route_info_item = quote_item!(ecx,
|
||||||
/// Rocket code generated static route information structure.
|
/// Rocket code generated static route information structure.
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
|
@ -277,6 +278,7 @@ fn generic_route_decorator(known_method: Option<Spanned<Method>>,
|
||||||
method: $method,
|
method: $method,
|
||||||
path: $path,
|
path: $path,
|
||||||
handler: $route_fn_name,
|
handler: $route_fn_name,
|
||||||
|
handler_name: $handler_name,
|
||||||
format: $media_type,
|
format: $media_type,
|
||||||
rank: $rank,
|
rank: $rank,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub struct StaticRouteInfo {
|
||||||
pub path: &'static str,
|
pub path: &'static str,
|
||||||
pub format: Option<MediaType>,
|
pub format: Option<MediaType>,
|
||||||
pub handler: Handler,
|
pub handler: Handler,
|
||||||
|
pub handler_name: &'static str,
|
||||||
pub rank: Option<isize>,
|
pub rank: Option<isize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ pub struct Route {
|
||||||
pub rank: isize,
|
pub rank: isize,
|
||||||
/// The media type this route matches against, if any.
|
/// The media type this route matches against, if any.
|
||||||
pub format: Option<MediaType>,
|
pub format: Option<MediaType>,
|
||||||
|
/// Static route information generated by codegen
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub route_info: Option<&'static StaticRouteInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -86,6 +89,7 @@ impl Route {
|
||||||
base: URI::from("/"),
|
base: URI::from("/"),
|
||||||
uri: uri,
|
uri: uri,
|
||||||
format: None,
|
format: None,
|
||||||
|
route_info: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +120,7 @@ impl Route {
|
||||||
uri: URI::from(uri.as_ref().to_string()),
|
uri: URI::from(uri.as_ref().to_string()),
|
||||||
rank: rank,
|
rank: rank,
|
||||||
format: None,
|
format: None,
|
||||||
|
route_info: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +232,7 @@ impl Clone for Route {
|
||||||
base: self.base.clone(),
|
base: self.base.clone(),
|
||||||
uri: self.uri.clone(),
|
uri: self.uri.clone(),
|
||||||
format: self.format.clone(),
|
format: self.format.clone(),
|
||||||
|
route_info: self.route_info.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,10 +260,11 @@ impl fmt::Debug for Route {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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 {
|
fn from(info: &'a StaticRouteInfo) -> Route {
|
||||||
let mut route = Route::new(info.method, info.path, info.handler);
|
let mut route = Route::new(info.method, info.path, info.handler);
|
||||||
route.format = info.format.clone();
|
route.format = info.format.clone();
|
||||||
|
route.route_info = Some(info);
|
||||||
if let Some(rank) = info.rank {
|
if let Some(rank) = info.rank {
|
||||||
route.rank = rank;
|
route.rank = rank;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue