mirror of https://github.com/rwf2/Rocket.git
Rename codegen proxy struct methods.
Also fixes codegen so that rustc emits a warning on unused catchers, as with routes in the previous commit.
This commit is contained in:
parent
d4466b73af
commit
691d3f2d95
|
@ -61,9 +61,9 @@ pub fn _catch(
|
|||
/// Rocket code generated proxy structure.
|
||||
#vis struct #user_catcher_fn_name { }
|
||||
|
||||
/// Rocket code generated proxy static conversion implementation.
|
||||
impl From<#user_catcher_fn_name> for #_catcher::StaticInfo {
|
||||
fn from(_: #user_catcher_fn_name) -> #_catcher::StaticInfo {
|
||||
/// Rocket code generated proxy static conversion implementations.
|
||||
impl #user_catcher_fn_name {
|
||||
fn into_info(self) -> #_catcher::StaticInfo {
|
||||
fn monomorphized_function<'_b>(
|
||||
#__status: #Status,
|
||||
#__req: &'_b #Request<'_>
|
||||
|
@ -83,13 +83,10 @@ pub fn _catch(
|
|||
handler: monomorphized_function,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Rocket code generated proxy conversion implementation.
|
||||
impl From<#user_catcher_fn_name> for #Catcher {
|
||||
#[inline]
|
||||
fn from(_: #user_catcher_fn_name) -> #Catcher {
|
||||
#_catcher::StaticInfo::from(#user_catcher_fn_name {}).into()
|
||||
#[doc(hidden)]
|
||||
pub fn into_catcher(self) -> #Catcher {
|
||||
self.into_info().into()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -335,7 +335,7 @@ fn codegen_route(route: Route) -> Result<TokenStream> {
|
|||
/// Rocket code generated proxy structure.
|
||||
#vis struct #handler_fn_name { }
|
||||
|
||||
/// Rocket code generated proxy static conversion implementation.
|
||||
/// Rocket code generated proxy static conversion implementations.
|
||||
impl #handler_fn_name {
|
||||
#[allow(non_snake_case, unreachable_patterns, unreachable_code)]
|
||||
fn into_info(self) -> #_route::StaticInfo {
|
||||
|
@ -363,7 +363,9 @@ fn codegen_route(route: Route) -> Result<TokenStream> {
|
|||
sentinels: #sentinels,
|
||||
}
|
||||
}
|
||||
pub fn into(self) -> #Route {
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn into_route(self) -> #Route {
|
||||
self.into_info().into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,17 +11,20 @@ mod test_guide;
|
|||
fn struct_maker_vec(
|
||||
input: proc_macro::TokenStream,
|
||||
ty: TokenStream,
|
||||
map: impl Fn(TokenStream) -> TokenStream,
|
||||
) -> Result<TokenStream> {
|
||||
use crate::exports::_Vec;
|
||||
|
||||
// Parse a comma-separated list of paths.
|
||||
let paths = <Punctuated<Path, Token![,]>>::parse_terminated.parse(input)?;
|
||||
let exprs = paths.iter()
|
||||
.map(|path| quote_spanned!(path.span() => {
|
||||
let exprs = paths.iter().map(|path| {
|
||||
let expr = map(quote_spanned!(path.span() => ___struct));
|
||||
quote_spanned!(path.span() => {
|
||||
let ___struct = #path {};
|
||||
let ___item: #ty = ___struct.into();
|
||||
let ___item: #ty = #expr;
|
||||
___item
|
||||
}));
|
||||
})
|
||||
});
|
||||
|
||||
Ok(quote!({
|
||||
let ___vec: #_Vec<#ty> = vec![#(#exprs),*];
|
||||
|
@ -30,12 +33,12 @@ fn struct_maker_vec(
|
|||
}
|
||||
|
||||
pub fn routes_macro(input: proc_macro::TokenStream) -> TokenStream {
|
||||
struct_maker_vec(input, quote!(::rocket::Route))
|
||||
struct_maker_vec(input, quote!(::rocket::Route), |e| quote!(#e.into_route()))
|
||||
.unwrap_or_else(|diag| diag.emit_as_expr_tokens())
|
||||
}
|
||||
|
||||
pub fn catchers_macro(input: proc_macro::TokenStream) -> TokenStream {
|
||||
struct_maker_vec(input, quote!(::rocket::Catcher))
|
||||
struct_maker_vec(input, quote!(::rocket::Catcher), |e| quote!(#e.into_catcher()))
|
||||
.unwrap_or_else(|diag| diag.emit_as_expr_tokens())
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ fn default_catcher(status: Status, req: &Request<'_>) -> status::Custom<String>
|
|||
status::Custom(status, msg)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[get("/unmanaged")]
|
||||
fn unmanaged(_u8: rocket::State<'_, u8>, _string: rocket::State<'_, String>) { }
|
||||
|
||||
|
|
Loading…
Reference in New Issue