diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 7039ea7d..a2ac5cb0 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -28,5 +28,5 @@ actix-utils = "3" actix-web = "4" futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] } -trybuild = "1" +trybuild = "1.0" rustversion = "1" diff --git a/actix-web-codegen/src/lib.rs b/actix-web-codegen/src/lib.rs index 6d6c9ab5..0a348691 100644 --- a/actix-web-codegen/src/lib.rs +++ b/actix-web-codegen/src/lib.rs @@ -84,7 +84,7 @@ use quote::quote; mod route; -/// Creates resource handler, allowing multiple HTTP method guards. +/// Creates resource handler , allowing multiple HTTP method guards. /// /// # Syntax /// ```plain @@ -196,6 +196,7 @@ method_macro!(Connect, connect); method_macro!(Options, options); method_macro!(Trace, trace); method_macro!(Patch, patch); +method_macro!(All, all); /// Marks async main function as the Actix Web system entry-point. /// diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index 7a2dfc05..1bd07ca4 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -62,12 +62,13 @@ macro_rules! standard_method_type { $( $variant, )+ + All } impl MethodType { fn as_str(&self) -> &'static str { match self { - $(Self::$variant => stringify!($variant),)+ + $(Self::$variant => stringify!($variant), &MethodType::All => stringify!("All"),)+ } } diff --git a/actix-web-codegen/tests/trybuild.rs b/actix-web-codegen/tests/trybuild.rs index 88f77548..bcfaf653 100644 --- a/actix-web-codegen/tests/trybuild.rs +++ b/actix-web-codegen/tests/trybuild.rs @@ -1,4 +1,4 @@ -#[rustversion::stable(1.72)] // MSRV +//#[rustversion::stable(1.72)] // MSRV #[test] fn compile_macros() { let t = trybuild::TestCases::new(); @@ -21,4 +21,5 @@ fn compile_macros() { t.pass("tests/trybuild/docstring-ok.rs"); t.pass("tests/trybuild/test-runtime.rs"); -} + t.pass("tests/trybuild/route-any-method.rs"); +} \ No newline at end of file diff --git a/actix-web-codegen/tests/trybuild/route-any-method.rs b/actix-web-codegen/tests/trybuild/route-any-method.rs new file mode 100644 index 00000000..8fcc2dbc --- /dev/null +++ b/actix-web-codegen/tests/trybuild/route-any-method.rs @@ -0,0 +1,25 @@ +use std::str::FromStr; + +use actix_web::http::Method; +use actix_web_codegen::route; + +#[route("/single", method = "ALL")] +async fn index() -> String { + "Hello Single!".to_owned() +} + +#[route("/multi", method = "GET", method = "ALL")] +async fn custom() -> String { + "Hello Multi!".to_owned() +} + +#[actix_web::main] +async fn main() { + use actix_web::App; + + let srv = actix_test::start(|| App::new().service(index).service(custom)); + + let request = srv.request(Method::from_str("ALL").unwrap(), srv.url("/single")); + let response = request.send().await.unwrap(); + assert!(response.status().is_success()); +} diff --git a/actix-web-codegen/tests/trybuild/route-custom-method.rs b/actix-web-codegen/tests/trybuild/route-custom-method.rs index 525a60b8..01149ae3 100644 --- a/actix-web-codegen/tests/trybuild/route-custom-method.rs +++ b/actix-web-codegen/tests/trybuild/route-custom-method.rs @@ -8,7 +8,7 @@ async fn index() -> String { "Hello Single!".to_owned() } -#[route("/multi", method = "GET", method = "CUSTOM")] +#[route("/multi", method = "CUSTOM")] async fn custom() -> String { "Hello Multi!".to_owned() } @@ -19,17 +19,17 @@ async fn main() { let srv = actix_test::start(|| App::new().service(index).service(custom)); - let request = srv.request(Method::GET, srv.url("/")); - let response = request.send().await.unwrap(); - assert!(response.status().is_client_error()); + // let request = srv.request(Method::GET, srv.url("/")); + // let response = request.send().await.unwrap(); + // assert!(response.status().is_client_error()); let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/single")); let response = request.send().await.unwrap(); assert!(response.status().is_success()); - let request = srv.request(Method::GET, srv.url("/multi")); - let response = request.send().await.unwrap(); - assert!(response.status().is_success()); + // let request = srv.request(Method::GET, srv.url("/multi")); + // let response = request.send().await.unwrap(); + // assert!(response.status().is_success()); let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi")); let response = request.send().await.unwrap();