mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-19 00:00:14 +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()
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use axum::{response::Html, routing::get, Router};
|
||||
use axum_macros::Route;
|
||||
use axum_macros::Uri;
|
||||
use serde::Deserialize;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -29,12 +29,12 @@ async fn handler(_: UsersShow) -> Html<&'static str> {
|
||||
Html("<h1>Hello, World!</h1>")
|
||||
}
|
||||
|
||||
// #[derive(Deserialize, Route)]
|
||||
// #[route("/users")]
|
||||
// struct UsersIndex;
|
||||
#[derive(Deserialize, Uri)]
|
||||
#[uri("/users")]
|
||||
struct UsersIndex;
|
||||
|
||||
#[derive(Deserialize, Route)]
|
||||
#[route("/users/:id/teams/:team_id")]
|
||||
#[derive(Deserialize, Uri)]
|
||||
#[uri("/users/:id/teams/:team_id")]
|
||||
struct UsersShow {
|
||||
id: u32,
|
||||
team_id: u32,
|
||||
|
||||
Reference in New Issue
Block a user