accept idents and exprs

This commit is contained in:
realaravinth 2021-05-25 11:40:03 +05:30
parent b91607bfb2
commit af3b62cbbb
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
2 changed files with 15 additions and 2 deletions

View File

@ -88,6 +88,7 @@ trait PathMarker: quote::ToTokens {}
impl PathMarker for syn::Ident {}
impl PathMarker for syn::LitStr {}
impl PathMarker for syn::Expr {}
impl Args {
fn new(args: AttributeArgs, method: Option<MethodType>) -> syn::Result<Self> {
@ -130,8 +131,7 @@ impl Args {
if let syn::Lit::Str(lit) = nv.lit {
match path {
None => {
let x = Ident::new(&lit.value(), Span::call_site());
path = Some(Box::new(x));
path = Some(Box::new(lit.parse::<syn::Expr>()?));
}
_ => {
return Err(syn::Error::new_spanned(

View File

@ -25,6 +25,14 @@ async fn path() -> impl Responder {
HttpResponse::Ok()
}
struct FieldPath(&'static str);
const FIELD_PATH: FieldPath = FieldPath("/path/new/");
#[get(path = "FIELD_PATH.0")]
async fn field_path() -> impl Responder {
HttpResponse::Ok()
}
#[get("/test")]
async fn test_handler() -> impl Responder {
HttpResponse::Ok()
@ -165,7 +173,12 @@ async fn test_params() {
.service(put_param_test)
.service(delete_param_test)
.service(path)
.service(field_path)
});
let request = srv.request(http::Method::GET, srv.url(FIELD_PATH.0));
let response = request.send().await.unwrap();
assert_eq!(response.status(), http::StatusCode::OK);
let request = srv.request(http::Method::GET, srv.url(PATH));
let response = request.send().await.unwrap();
assert_eq!(response.status(), http::StatusCode::OK);