mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
wip
This commit is contained in:
@@ -49,7 +49,7 @@ use syn::parse::Parse;
|
||||
|
||||
mod debug_handler;
|
||||
mod from_request;
|
||||
mod route;
|
||||
mod uri;
|
||||
|
||||
/// Derive an implementation of [`FromRequest`].
|
||||
///
|
||||
@@ -387,8 +387,8 @@ pub fn debug_handler(_attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[proc_macro_derive(Route, attributes(route))]
|
||||
pub fn derive_route(input: TokenStream) -> TokenStream {
|
||||
#[proc_macro_derive(Uri, attributes(uri))]
|
||||
pub fn derive_uri(input: TokenStream) -> TokenStream {
|
||||
expand_with(input, route::expand)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ fn parse_attrs(attrs: &[syn::Attribute]) -> syn::Result<Attrs> {
|
||||
let mut route = None::<String>;
|
||||
|
||||
for attr in attrs {
|
||||
if attr.path.is_ident("route") {
|
||||
if attr.path.is_ident("uri") {
|
||||
route = Some(attr.parse_args::<LitStr>()?.value());
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,8 @@ fn route_method(route: &str, vis: &syn::Visibility, fields: &syn::Fields) -> Tok
|
||||
});
|
||||
|
||||
quote! {
|
||||
#vis fn route(&self) -> String {
|
||||
format!(#format_str, #(#set_placeholders,)*)
|
||||
#vis fn path(&self) -> ::std::borrow::Cow<'static, str> {
|
||||
format!(#format_str, #(#set_placeholders,)*).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,14 +85,14 @@ fn route_method(route: &str, vis: &syn::Visibility, fields: &syn::Fields) -> Tok
|
||||
});
|
||||
|
||||
quote! {
|
||||
#vis fn route(&self) -> String {
|
||||
format!(#format_str, #(#set_placeholders,)*)
|
||||
#vis fn path(&self) -> ::std::borrow::Cow<'static, str> {
|
||||
format!(#format_str, #(#set_placeholders,)*).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
syn::Fields::Unit => quote! {
|
||||
#vis fn route(&self) -> &'static str {
|
||||
#route
|
||||
#vis fn uri(&self) -> ::std::borrow::Cow<'static, str> {
|
||||
#route.into()
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user