1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-17 05:36:36 +00:00

Update: Draft

This commit is contained in:
Sabin 2024-03-16 16:44:19 +05:45
parent 52b0d5fbf9
commit b57b9bfa7d
6 changed files with 40 additions and 12 deletions

View file

@ -28,5 +28,5 @@ actix-utils = "3"
actix-web = "4" actix-web = "4"
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] } futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
trybuild = "1" trybuild = "1.0"
rustversion = "1" rustversion = "1"

View file

@ -196,6 +196,7 @@ method_macro!(Connect, connect);
method_macro!(Options, options); method_macro!(Options, options);
method_macro!(Trace, trace); method_macro!(Trace, trace);
method_macro!(Patch, patch); method_macro!(Patch, patch);
method_macro!(All, all);
/// Marks async main function as the Actix Web system entry-point. /// Marks async main function as the Actix Web system entry-point.
/// ///

View file

@ -62,12 +62,13 @@ macro_rules! standard_method_type {
$( $(
$variant, $variant,
)+ )+
All
} }
impl MethodType { impl MethodType {
fn as_str(&self) -> &'static str { fn as_str(&self) -> &'static str {
match self { match self {
$(Self::$variant => stringify!($variant),)+ $(Self::$variant => stringify!($variant), &MethodType::All => stringify!("All"),)+
} }
} }

View file

@ -1,4 +1,4 @@
#[rustversion::stable(1.72)] // MSRV //#[rustversion::stable(1.72)] // MSRV
#[test] #[test]
fn compile_macros() { fn compile_macros() {
let t = trybuild::TestCases::new(); let t = trybuild::TestCases::new();
@ -21,4 +21,5 @@ fn compile_macros() {
t.pass("tests/trybuild/docstring-ok.rs"); t.pass("tests/trybuild/docstring-ok.rs");
t.pass("tests/trybuild/test-runtime.rs"); t.pass("tests/trybuild/test-runtime.rs");
t.pass("tests/trybuild/route-any-method.rs");
} }

View file

@ -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());
}

View file

@ -8,7 +8,7 @@ async fn index() -> String {
"Hello Single!".to_owned() "Hello Single!".to_owned()
} }
#[route("/multi", method = "GET", method = "CUSTOM")] #[route("/multi", method = "CUSTOM")]
async fn custom() -> String { async fn custom() -> String {
"Hello Multi!".to_owned() "Hello Multi!".to_owned()
} }
@ -19,17 +19,17 @@ async fn main() {
let srv = actix_test::start(|| App::new().service(index).service(custom)); let srv = actix_test::start(|| App::new().service(index).service(custom));
let request = srv.request(Method::GET, srv.url("/")); // let request = srv.request(Method::GET, srv.url("/"));
let response = request.send().await.unwrap(); // let response = request.send().await.unwrap();
assert!(response.status().is_client_error()); // assert!(response.status().is_client_error());
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/single")); let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/single"));
let response = request.send().await.unwrap(); let response = request.send().await.unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
let request = srv.request(Method::GET, srv.url("/multi")); // let request = srv.request(Method::GET, srv.url("/multi"));
let response = request.send().await.unwrap(); // let response = request.send().await.unwrap();
assert!(response.status().is_success()); // assert!(response.status().is_success());
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi")); let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi"));
let response = request.send().await.unwrap(); let response = request.send().await.unwrap();