mirror of https://github.com/fafhrd91/actix-web
Merge e9ca0b8296
into 265fa0d050
This commit is contained in:
commit
9c960f6327
|
@ -1,6 +1,9 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
- Preserve function visibility for routing macros. [#2714]
|
||||||
|
|
||||||
|
[#2714]: https://github.com/actix/actix-web/pull/2714
|
||||||
|
|
||||||
|
|
||||||
## 4.0.1 - 2022-06-11
|
## 4.0.1 - 2022-06-11
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
//!
|
//!
|
||||||
//! # Single Method Handler
|
//! # Single Method Handler
|
||||||
//! There is a macro to set up a handler for each of the most common HTTP methods that also define
|
//! There is a macro to set up a handler for each of the most common HTTP methods that also define
|
||||||
//! additional guards and route-specific middleware.
|
//! additional guards and route-specific middleware. This macros will inherit the visibility
|
||||||
|
//! of the underlying handler.
|
||||||
//!
|
//!
|
||||||
//! See docs for: [GET], [POST], [PATCH], [PUT], [DELETE], [HEAD], [CONNECT], [OPTIONS], [TRACE]
|
//! See docs for: [GET], [POST], [PATCH], [PUT], [DELETE], [HEAD], [CONNECT], [OPTIONS], [TRACE]
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -291,6 +291,7 @@ impl ToTokens for Route {
|
||||||
resource_type,
|
resource_type,
|
||||||
doc_attributes,
|
doc_attributes,
|
||||||
} = self;
|
} = self;
|
||||||
|
let visibility = &ast.vis;
|
||||||
let resource_name = resource_name
|
let resource_name = resource_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or_else(|| name.to_string(), LitStr::value);
|
.map_or_else(|| name.to_string(), LitStr::value);
|
||||||
|
@ -316,7 +317,7 @@ impl ToTokens for Route {
|
||||||
let stream = quote! {
|
let stream = quote! {
|
||||||
#(#doc_attributes)*
|
#(#doc_attributes)*
|
||||||
#[allow(non_camel_case_types, missing_docs)]
|
#[allow(non_camel_case_types, missing_docs)]
|
||||||
pub struct #name;
|
#visibility struct #name;
|
||||||
|
|
||||||
impl ::actix_web::dev::HttpServiceFactory for #name {
|
impl ::actix_web::dev::HttpServiceFactory for #name {
|
||||||
fn register(self, __config: &mut actix_web::dev::AppService) {
|
fn register(self, __config: &mut actix_web::dev::AppService) {
|
||||||
|
|
|
@ -6,6 +6,9 @@ fn compile_macros() {
|
||||||
t.pass("tests/trybuild/simple.rs");
|
t.pass("tests/trybuild/simple.rs");
|
||||||
t.compile_fail("tests/trybuild/simple-fail.rs");
|
t.compile_fail("tests/trybuild/simple-fail.rs");
|
||||||
|
|
||||||
|
t.pass("tests/trybuild/visibility-ok.rs");
|
||||||
|
t.compile_fail("tests/trybuild/visibility-fail.rs");
|
||||||
|
|
||||||
t.pass("tests/trybuild/route-ok.rs");
|
t.pass("tests/trybuild/route-ok.rs");
|
||||||
t.compile_fail("tests/trybuild/route-missing-method-fail.rs");
|
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-duplicate-method-fail.rs");
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
use actix_web::App;
|
||||||
|
|
||||||
|
mod config {
|
||||||
|
use actix_web_codegen::*;
|
||||||
|
use actix_web::{Responder, HttpResponse};
|
||||||
|
|
||||||
|
#[get("/config")]
|
||||||
|
async fn config() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = actix_test::start(|| App::new().service(config::config));
|
||||||
|
|
||||||
|
let request = srv.get("/config");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0603]: unit struct `config` is private
|
||||||
|
--> tests/trybuild/visibility-fail.rs:15:63
|
||||||
|
|
|
||||||
|
15 | let srv = actix_test::start(|| App::new().service(config::config));
|
||||||
|
| ^^^^^^ private unit struct
|
||||||
|
|
|
||||||
|
note: the unit struct `config` is defined here
|
||||||
|
--> tests/trybuild/visibility-fail.rs:7:5
|
||||||
|
|
|
||||||
|
7 | #[get("/config")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the attribute macro `get` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -0,0 +1,20 @@
|
||||||
|
use actix_web::App;
|
||||||
|
|
||||||
|
mod config {
|
||||||
|
use actix_web_codegen::*;
|
||||||
|
use actix_web::{Responder, HttpResponse};
|
||||||
|
|
||||||
|
#[get("/config")]
|
||||||
|
pub async fn config() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = actix_test::start(|| App::new().service(config::config));
|
||||||
|
|
||||||
|
let request = srv.get("/config");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
Loading…
Reference in New Issue