compile time validation of path

This commit is contained in:
realaravinth 2021-07-29 10:46:18 +05:30
parent 293c52c3ef
commit 2039d42a55
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
4 changed files with 11 additions and 0 deletions

View File

@ -17,6 +17,7 @@ proc-macro = true
quote = "1"
syn = { version = "1", features = ["full", "parsing"] }
proc-macro2 = "1"
actix-router = "0.2.7"
[dev-dependencies]
actix-rt = "2.2"

View File

@ -3,6 +3,7 @@ extern crate proc_macro;
use std::collections::HashSet;
use std::convert::TryFrom;
use actix_router::ResourceDef;
use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
@ -113,6 +114,7 @@ impl Args {
NestedMeta::Meta(syn::Meta::NameValue(nv)) => {
if nv.path.is_ident("name") {
if let syn::Lit::Str(lit) = nv.lit {
let _ = ResourceDef::new(lit.value());
resource_name = Some(lit);
} else {
return Err(syn::Error::new_spanned(

View File

@ -10,6 +10,7 @@ fn compile_macros() {
t.compile_fail("tests/trybuild/route-missing-method-fail.rs");
t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs");
t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs");
t.compile_fail("tests/trybuild/route-malformed-path-fail.rs");
t.pass("tests/trybuild/docstring-ok.rs");
}

View File

@ -0,0 +1,7 @@
use actix_web_codegen::*;
#[get("/one/{", other)]
async fn one() -> String {
"Hello World!".to_owned()
}
fn main() {}