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.
|
/// Rocket code generated proxy structure.
|
||||||
#vis struct #user_catcher_fn_name { }
|
#vis struct #user_catcher_fn_name { }
|
||||||
|
|
||||||
/// Rocket code generated proxy static conversion implementation.
|
/// Rocket code generated proxy static conversion implementations.
|
||||||
impl From<#user_catcher_fn_name> for #_catcher::StaticInfo {
|
impl #user_catcher_fn_name {
|
||||||
fn from(_: #user_catcher_fn_name) -> #_catcher::StaticInfo {
|
fn into_info(self) -> #_catcher::StaticInfo {
|
||||||
fn monomorphized_function<'_b>(
|
fn monomorphized_function<'_b>(
|
||||||
#__status: #Status,
|
#__status: #Status,
|
||||||
#__req: &'_b #Request<'_>
|
#__req: &'_b #Request<'_>
|
||||||
|
@ -83,13 +83,10 @@ pub fn _catch(
|
||||||
handler: monomorphized_function,
|
handler: monomorphized_function,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Rocket code generated proxy conversion implementation.
|
#[doc(hidden)]
|
||||||
impl From<#user_catcher_fn_name> for #Catcher {
|
pub fn into_catcher(self) -> #Catcher {
|
||||||
#[inline]
|
self.into_info().into()
|
||||||
fn from(_: #user_catcher_fn_name) -> #Catcher {
|
|
||||||
#_catcher::StaticInfo::from(#user_catcher_fn_name {}).into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -335,7 +335,7 @@ fn codegen_route(route: Route) -> Result<TokenStream> {
|
||||||
/// Rocket code generated proxy structure.
|
/// Rocket code generated proxy structure.
|
||||||
#vis struct #handler_fn_name { }
|
#vis struct #handler_fn_name { }
|
||||||
|
|
||||||
/// Rocket code generated proxy static conversion implementation.
|
/// Rocket code generated proxy static conversion implementations.
|
||||||
impl #handler_fn_name {
|
impl #handler_fn_name {
|
||||||
#[allow(non_snake_case, unreachable_patterns, unreachable_code)]
|
#[allow(non_snake_case, unreachable_patterns, unreachable_code)]
|
||||||
fn into_info(self) -> #_route::StaticInfo {
|
fn into_info(self) -> #_route::StaticInfo {
|
||||||
|
@ -363,7 +363,9 @@ fn codegen_route(route: Route) -> Result<TokenStream> {
|
||||||
sentinels: #sentinels,
|
sentinels: #sentinels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn into(self) -> #Route {
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn into_route(self) -> #Route {
|
||||||
self.into_info().into()
|
self.into_info().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,17 +11,20 @@ mod test_guide;
|
||||||
fn struct_maker_vec(
|
fn struct_maker_vec(
|
||||||
input: proc_macro::TokenStream,
|
input: proc_macro::TokenStream,
|
||||||
ty: TokenStream,
|
ty: TokenStream,
|
||||||
|
map: impl Fn(TokenStream) -> TokenStream,
|
||||||
) -> Result<TokenStream> {
|
) -> Result<TokenStream> {
|
||||||
use crate::exports::_Vec;
|
use crate::exports::_Vec;
|
||||||
|
|
||||||
// Parse a comma-separated list of paths.
|
// Parse a comma-separated list of paths.
|
||||||
let paths = <Punctuated<Path, Token![,]>>::parse_terminated.parse(input)?;
|
let paths = <Punctuated<Path, Token![,]>>::parse_terminated.parse(input)?;
|
||||||
let exprs = paths.iter()
|
let exprs = paths.iter().map(|path| {
|
||||||
.map(|path| quote_spanned!(path.span() => {
|
let expr = map(quote_spanned!(path.span() => ___struct));
|
||||||
|
quote_spanned!(path.span() => {
|
||||||
let ___struct = #path {};
|
let ___struct = #path {};
|
||||||
let ___item: #ty = ___struct.into();
|
let ___item: #ty = #expr;
|
||||||
___item
|
___item
|
||||||
}));
|
})
|
||||||
|
});
|
||||||
|
|
||||||
Ok(quote!({
|
Ok(quote!({
|
||||||
let ___vec: #_Vec<#ty> = vec![#(#exprs),*];
|
let ___vec: #_Vec<#ty> = vec![#(#exprs),*];
|
||||||
|
@ -30,12 +33,12 @@ fn struct_maker_vec(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn routes_macro(input: proc_macro::TokenStream) -> TokenStream {
|
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())
|
.unwrap_or_else(|diag| diag.emit_as_expr_tokens())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn catchers_macro(input: proc_macro::TokenStream) -> TokenStream {
|
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())
|
.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)
|
status::Custom(status, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[get("/unmanaged")]
|
#[get("/unmanaged")]
|
||||||
fn unmanaged(_u8: rocket::State<'_, u8>, _string: rocket::State<'_, String>) { }
|
fn unmanaged(_u8: rocket::State<'_, u8>, _string: rocket::State<'_, String>) { }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue