mirror of https://github.com/fafhrd91/actix-web
accept idents and exprs
This commit is contained in:
parent
b91607bfb2
commit
af3b62cbbb
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue