From f6393728c7d4a820ab9cfff81a1cf627a2007889 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 24 Feb 2021 09:08:56 +0000 Subject: [PATCH 1/3] remove usage of actix_utils::mpsc (#2023) --- actix-multipart/Cargo.toml | 4 +++- actix-multipart/src/server.rs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index 67b2698bd..f3bb92336 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -22,7 +22,7 @@ actix-utils = "3.0.0-beta.2" bytes = "1" derive_more = "0.99.5" httparse = "1.3" -futures-util = { version = "0.3.7", default-features = false } +futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] } log = "0.4" mime = "0.3" twoway = "0.2" @@ -30,3 +30,5 @@ twoway = "0.2" [dev-dependencies] actix-rt = "2" actix-http = "3.0.0-beta.3" +tokio = { version = "1", features = ["sync"] } +tokio-stream = "0.1" diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index 8cd1c8e0c..d9ff3d574 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -804,12 +804,13 @@ mod tests { use super::*; use actix_http::h1::Payload; - use actix_utils::mpsc; use actix_web::http::header::{DispositionParam, DispositionType}; use actix_web::test::TestRequest; use actix_web::FromRequest; use bytes::Bytes; use futures_util::future::lazy; + use tokio::sync::mpsc; + use tokio_stream::wrappers::UnboundedReceiverStream; #[actix_rt::test] async fn test_boundary() { @@ -855,13 +856,17 @@ mod tests { } fn create_stream() -> ( - mpsc::Sender>, + mpsc::UnboundedSender>, impl Stream>, ) { - let (tx, rx) = mpsc::channel(); + let (tx, rx) = mpsc::unbounded_channel(); - (tx, rx.map(|res| res.map_err(|_| panic!()))) + ( + tx, + UnboundedReceiverStream::new(rx).map(|res| res.map_err(|_| panic!())), + ) } + // Stream that returns from a Bytes, one char at a time and Pending every other poll() struct SlowStream { bytes: Bytes, @@ -889,9 +894,11 @@ mod tests { cx.waker().wake_by_ref(); return Poll::Pending; } + if this.pos == this.bytes.len() { return Poll::Ready(None); } + let res = Poll::Ready(Some(Ok(this.bytes.slice(this.pos..(this.pos + 1))))); this.pos += 1; this.ready = false; From 42711c23d75fb53d1daf2eadaa15489e386e170b Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 24 Feb 2021 12:26:56 +0000 Subject: [PATCH 2/3] Port over doc comments in route macros. (#2022) Co-authored-by: Jonas Platte Co-authored-by: Rob Ede --- actix-web-codegen/CHANGES.md | 3 +++ actix-web-codegen/src/route.rs | 18 ++++++++++++++++++ actix-web-codegen/tests/trybuild.rs | 2 ++ .../tests/trybuild/docstring-ok.rs | 17 +++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 actix-web-codegen/tests/trybuild/docstring-ok.rs diff --git a/actix-web-codegen/CHANGES.md b/actix-web-codegen/CHANGES.md index 2ce728aad..f1dbf8e5f 100644 --- a/actix-web-codegen/CHANGES.md +++ b/actix-web-codegen/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Preserve doc comments when using route macros. [#2022] + +[#2022]: https://github.com/actix/actix-web/pull/2022 ## 0.5.0-beta.1 - 2021-02-10 diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index ddbd42454..e3c5f0368 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -176,6 +176,9 @@ pub struct Route { args: Args, ast: syn::ItemFn, resource_type: ResourceType, + + /// The doc comment attributes to copy to generated struct, if any. + doc_attributes: Vec, } fn guess_resource_type(typ: &syn::Type) -> ResourceType { @@ -221,6 +224,18 @@ impl Route { let ast: syn::ItemFn = syn::parse(input)?; let name = ast.sig.ident.clone(); + // Try and pull out the doc comments so that we can reapply them to the + // generated struct. + // + // Note that multi line doc comments are converted to multiple doc + // attributes. + let doc_attributes = ast + .attrs + .iter() + .filter(|attr| attr.path.is_ident("doc")) + .cloned() + .collect(); + let args = Args::new(args, method)?; if args.methods.is_empty() { return Err(syn::Error::new( @@ -248,6 +263,7 @@ impl Route { args, ast, resource_type, + doc_attributes, }) } } @@ -265,6 +281,7 @@ impl ToTokens for Route { methods, }, resource_type, + doc_attributes, } = self; let resource_name = name.to_string(); let method_guards = { @@ -287,6 +304,7 @@ impl ToTokens for Route { }; let stream = quote! { + #(#doc_attributes)* #[allow(non_camel_case_types, missing_docs)] pub struct #name; diff --git a/actix-web-codegen/tests/trybuild.rs b/actix-web-codegen/tests/trybuild.rs index d2d8a38f5..afbe7b728 100644 --- a/actix-web-codegen/tests/trybuild.rs +++ b/actix-web-codegen/tests/trybuild.rs @@ -9,6 +9,8 @@ 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.pass("tests/trybuild/docstring-ok.rs"); } // #[rustversion::not(nightly)] diff --git a/actix-web-codegen/tests/trybuild/docstring-ok.rs b/actix-web-codegen/tests/trybuild/docstring-ok.rs new file mode 100644 index 000000000..2910976c7 --- /dev/null +++ b/actix-web-codegen/tests/trybuild/docstring-ok.rs @@ -0,0 +1,17 @@ +use actix_web::{Responder, HttpResponse, App, test}; +use actix_web_codegen::*; + +/// Docstrings shouldn't break anything. +#[get("/")] +async fn index() -> impl Responder { + HttpResponse::Ok() +} + +#[actix_web::main] +async fn main() { + let srv = test::start(|| App::new().service(index)); + + let request = srv.get("/"); + let response = request.send().await.unwrap(); + assert!(response.status().is_success()); +} From ebaf25d55a6bd62fc26472ec17184ccc7a574a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baran=20Demirba=C5=9F?= <77154643+barandemirbas@users.noreply.github.com> Date: Wed, 24 Feb 2021 19:19:40 +0300 Subject: [PATCH 3/3] Fix typos in CHANGES.md (#2025) Co-authored-by: Rob Ede --- CHANGES.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7cb03c30c..819237ab7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -168,7 +168,7 @@ ## 3.0.0-beta.4 - 2020-09-09 ### Added -* `middleware::NormalizePath` now has configurable behaviour for either always having a trailing +* `middleware::NormalizePath` now has configurable behavior for either always having a trailing slash, or as the new addition, always trimming trailing slashes. [#1639] ### Changed @@ -496,7 +496,7 @@ ## [1.0.0-rc] - 2019-05-18 -### Add +### Added * Add `Query::from_query()` to extract parameters from a query string. #846 * `QueryConfig`, similar to `JsonConfig` for customizing error handling of query extractors. @@ -512,7 +512,7 @@ ## [1.0.0-beta.4] - 2019-05-12 -### Add +### Added * Allow to set/override app data on scope level @@ -538,7 +538,7 @@ * CORS handling without headers #702 -* Allow to construct `Data` instances to avoid double `Arc` for `Send + Sync` types. +* Allow constructing `Data` instances to avoid double `Arc` for `Send + Sync` types. ### Fixed @@ -602,7 +602,7 @@ ### Changed -* Allow to use any service as default service. +* Allow using any service as default service. * Remove generic type for request payload, always use default. @@ -665,13 +665,13 @@ ### Added -* rustls support +* Rustls support ### Changed -* use forked cookie +* Use forked cookie -* multipart::Field renamed to MultipartField +* Multipart::Field renamed to MultipartField ## [1.0.0-alpha.1] - 2019-03-28