diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 76c68ce25..95afb9ff1 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -952,9 +952,7 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_range_headers() { - let srv = test::start(|| { - App::new().service(Files::new("/", ".")) - }); + let srv = test::start(|| App::new().service(Files::new("/", "."))); // Valid range header let response = srv @@ -979,9 +977,7 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_length_headers() { - let srv = test::start(|| { - App::new().service(Files::new("/", ".")) - }); + let srv = test::start(|| App::new().service(Files::new("/", "."))); // Valid range header let response = srv @@ -1020,15 +1016,9 @@ mod tests { #[actix_rt::test] async fn test_head_content_length_headers() { - let srv = test::start(|| { - App::new().service(Files::new("/", ".")) - }); + let srv = test::start(|| App::new().service(Files::new("/", "."))); - let response = srv - .head("/tests/test.binary") - .send() - .await - .unwrap(); + let response = srv.head("/tests/test.binary").send().await.unwrap(); let content_length = response .headers() @@ -1097,12 +1087,10 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_encoding() { let mut srv = test::init_service(App::new().wrap(Compress::default()).service( - web::resource("/").to(|| { - async { - NamedFile::open("Cargo.toml") - .unwrap() - .set_content_encoding(header::ContentEncoding::Identity) - } + web::resource("/").to(|| async { + NamedFile::open("Cargo.toml") + .unwrap() + .set_content_encoding(header::ContentEncoding::Identity) }), )) .await; @@ -1119,12 +1107,10 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_encoding_gzip() { let mut srv = test::init_service(App::new().wrap(Compress::default()).service( - web::resource("/").to(|| { - async { - NamedFile::open("Cargo.toml") - .unwrap() - .set_content_encoding(header::ContentEncoding::Gzip) - } + web::resource("/").to(|| async { + NamedFile::open("Cargo.toml") + .unwrap() + .set_content_encoding(header::ContentEncoding::Gzip) }), )) .await; diff --git a/actix-http/src/body.rs b/actix-http/src/body.rs index 137f462a4..f35a294e7 100644 --- a/actix-http/src/body.rs +++ b/actix-http/src/body.rs @@ -22,9 +22,7 @@ pub enum BodySize { impl BodySize { pub fn is_eof(&self) -> bool { match self { - BodySize::None - | BodySize::Empty - | BodySize::Sized(0) => true, + BodySize::None | BodySize::Empty | BodySize::Sized(0) => true, _ => false, } } @@ -470,9 +468,9 @@ where #[cfg(test)] mod tests { use super::*; - use futures_util::stream; use futures_util::future::poll_fn; use futures_util::pin_mut; + use futures_util::stream; impl Body { pub(crate) fn get_ref(&self) -> &[u8] { diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index 7d1d3dc51..3f9a981f4 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -37,7 +37,10 @@ where trace!("Sending client request: {:?} {:?}", head, body.size()); let head_req = head.as_ref().method == Method::HEAD; let length = body.size(); - let eof = matches!(length, BodySize::None | BodySize::Empty | BodySize::Sized(0)); + let eof = matches!( + length, + BodySize::None | BodySize::Empty | BodySize::Sized(0) + ); let mut req = Request::new(()); *req.uri_mut() = head.as_ref().uri.clone(); diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 3ce443794..f2c5b0410 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -69,10 +69,7 @@ where inner: Rc::downgrade(&inner_rc), }); - ConnectionPool( - connector_rc, - inner_rc, - ) + ConnectionPool(connector_rc, inner_rc) } } diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index 4e3918537..96e01767b 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -72,7 +72,7 @@ impl fmt::Debug for Extensions { #[cfg(test)] mod tests { use super::*; - + #[test] fn test_remove() { let mut map = Extensions::new(); diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 33fb3a814..534ce928a 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -303,55 +303,59 @@ where } } }, - ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => loop { + ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => { loop { - if let Some(ref mut buffer) = this.buffer { - match stream.poll_capacity(cx) { - Poll::Pending => return Poll::Pending, - Poll::Ready(None) => return Poll::Ready(()), - Poll::Ready(Some(Ok(cap))) => { - let len = buffer.len(); - let bytes = buffer.split_to(std::cmp::min(cap, len)); + loop { + if let Some(ref mut buffer) = this.buffer { + match stream.poll_capacity(cx) { + Poll::Pending => return Poll::Pending, + Poll::Ready(None) => return Poll::Ready(()), + Poll::Ready(Some(Ok(cap))) => { + let len = buffer.len(); + let bytes = buffer.split_to(std::cmp::min(cap, len)); - if let Err(e) = stream.send_data(bytes, false) { + if let Err(e) = stream.send_data(bytes, false) { + warn!("{:?}", e); + return Poll::Ready(()); + } else if !buffer.is_empty() { + let cap = + std::cmp::min(buffer.len(), CHUNK_SIZE); + stream.reserve_capacity(cap); + } else { + this.buffer.take(); + } + } + Poll::Ready(Some(Err(e))) => { warn!("{:?}", e); return Poll::Ready(()); - } else if !buffer.is_empty() { - let cap = std::cmp::min(buffer.len(), CHUNK_SIZE); - stream.reserve_capacity(cap); - } else { - this.buffer.take(); } } - Poll::Ready(Some(Err(e))) => { - warn!("{:?}", e); - return Poll::Ready(()); - } - } - } else { - match body.as_mut().poll_next(cx) { - Poll::Pending => return Poll::Pending, - Poll::Ready(None) => { - if let Err(e) = stream.send_data(Bytes::new(), true) { - warn!("{:?}", e); + } else { + match body.as_mut().poll_next(cx) { + Poll::Pending => return Poll::Pending, + Poll::Ready(None) => { + if let Err(e) = stream.send_data(Bytes::new(), true) + { + warn!("{:?}", e); + } + return Poll::Ready(()); + } + Poll::Ready(Some(Ok(chunk))) => { + stream.reserve_capacity(std::cmp::min( + chunk.len(), + CHUNK_SIZE, + )); + *this.buffer = Some(chunk); + } + Poll::Ready(Some(Err(e))) => { + error!("Response payload stream error: {:?}", e); + return Poll::Ready(()); } - return Poll::Ready(()); - } - Poll::Ready(Some(Ok(chunk))) => { - stream.reserve_capacity(std::cmp::min( - chunk.len(), - CHUNK_SIZE, - )); - *this.buffer = Some(chunk); - } - Poll::Ready(Some(Err(e))) => { - error!("Response payload stream error: {:?}", e); - return Poll::Ready(()); } } } } - }, + } } } } diff --git a/actix-http/src/header/common/allow.rs b/actix-http/src/header/common/allow.rs index 432cc00d5..88c21763c 100644 --- a/actix-http/src/header/common/allow.rs +++ b/actix-http/src/header/common/allow.rs @@ -1,5 +1,5 @@ -use http::Method; use http::header; +use http::Method; header! { /// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1) diff --git a/actix-http/src/header/common/mod.rs b/actix-http/src/header/common/mod.rs index 08950ea8b..83489b864 100644 --- a/actix-http/src/header/common/mod.rs +++ b/actix-http/src/header/common/mod.rs @@ -9,11 +9,13 @@ pub use self::accept_charset::AcceptCharset; //pub use self::accept_encoding::AcceptEncoding; -pub use self::accept_language::AcceptLanguage; pub use self::accept::Accept; +pub use self::accept_language::AcceptLanguage; pub use self::allow::Allow; pub use self::cache_control::{CacheControl, CacheDirective}; -pub use self::content_disposition::{ContentDisposition, DispositionType, DispositionParam}; +pub use self::content_disposition::{ + ContentDisposition, DispositionParam, DispositionType, +}; pub use self::content_language::ContentLanguage; pub use self::content_range::{ContentRange, ContentRangeSpec}; pub use self::content_type::ContentType; @@ -47,7 +49,7 @@ macro_rules! __hyper__deref { &mut self.0 } } - } + }; } #[doc(hidden)] @@ -74,8 +76,8 @@ macro_rules! test_header { ($id:ident, $raw:expr) => { #[test] fn $id() { - use $crate::test; use super::*; + use $crate::test; let raw = $raw; let a: Vec> = raw.iter().map(|x| x.to_vec()).collect(); @@ -118,7 +120,7 @@ macro_rules! test_header { // Test formatting if typed.is_some() { let raw = &($raw)[..]; - let mut iter = raw.iter().map(|b|str::from_utf8(&b[..]).unwrap()); + let mut iter = raw.iter().map(|b| str::from_utf8(&b[..]).unwrap()); let mut joined = String::new(); joined.push_str(iter.next().unwrap()); for s in iter { @@ -128,7 +130,7 @@ macro_rules! test_header { assert_eq!(format!("{}", typed.unwrap()), joined); } } - } + }; } #[macro_export] @@ -330,11 +332,10 @@ macro_rules! header { }; } - mod accept_charset; //mod accept_encoding; -mod accept_language; mod accept; +mod accept_language; mod allow; mod cache_control; mod content_disposition; diff --git a/actix-http/tests/test_openssl.rs b/actix-http/tests/test_openssl.rs index 3a7bfa409..795deacdc 100644 --- a/actix-http/tests/test_openssl.rs +++ b/actix-http/tests/test_openssl.rs @@ -274,9 +274,7 @@ async fn test_h2_head_empty() { async fn test_h2_head_binary() { let mut srv = test_server(move || { HttpService::build() - .h2(|_| { - ok::<_, ()>(Response::Ok().body(STR)) - }) + .h2(|_| ok::<_, ()>(Response::Ok().body(STR))) .openssl(ssl_acceptor()) .map_err(|_| ()) }) diff --git a/actix-http/tests/test_rustls.rs b/actix-http/tests/test_rustls.rs index 465cba6df..beae359d9 100644 --- a/actix-http/tests/test_rustls.rs +++ b/actix-http/tests/test_rustls.rs @@ -280,9 +280,7 @@ async fn test_h2_head_empty() { async fn test_h2_head_binary() { let mut srv = test_server(move || { HttpService::build() - .h2(|_| { - ok::<_, ()>(Response::Ok().body(STR)) - }) + .h2(|_| ok::<_, ()>(Response::Ok().body(STR))) .rustls(ssl_acceptor()) }) .await; diff --git a/actix-http/tests/test_server.rs b/actix-http/tests/test_server.rs index bee5ebef2..0375b6f66 100644 --- a/actix-http/tests/test_server.rs +++ b/actix-http/tests/test_server.rs @@ -489,9 +489,7 @@ async fn test_h1_head_empty() { async fn test_h1_head_binary() { let mut srv = test_server(|| { HttpService::build() - .h1(|_| { - ok::<_, ()>(Response::Ok().body(STR)) - }) + .h1(|_| ok::<_, ()>(Response::Ok().body(STR))) .tcp() }) .await; diff --git a/actix-web-actors/tests/test_ws.rs b/actix-web-actors/tests/test_ws.rs index 25977c2c2..b575938f1 100644 --- a/actix-web-actors/tests/test_ws.rs +++ b/actix-web-actors/tests/test_ws.rs @@ -30,8 +30,8 @@ impl StreamHandler> for Ws { async fn test_simple() { let mut srv = test::start(|| { App::new().service(web::resource("/").to( - |req: HttpRequest, stream: web::Payload| { - async move { ws::start(Ws, &req, stream) } + |req: HttpRequest, stream: web::Payload| async move { + ws::start(Ws, &req, stream) }, )) }); diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index 7e3d43f1d..676e75e07 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -3,7 +3,7 @@ extern crate proc_macro; use proc_macro::TokenStream; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{format_ident, quote, ToTokens, TokenStreamExt}; -use syn::{AttributeArgs, Ident, NestedMeta, parse_macro_input}; +use syn::{parse_macro_input, AttributeArgs, Ident, NestedMeta}; enum ResourceType { Async, @@ -196,7 +196,12 @@ impl ToTokens for Route { name, guard, ast, - args: Args { path, guards, wrappers }, + args: + Args { + path, + guards, + wrappers, + }, resource_type, } = self; let resource_name = name.to_string(); diff --git a/actix-web-codegen/tests/test_macro.rs b/actix-web-codegen/tests/test_macro.rs index 0ef7e1c75..e959b2bc7 100644 --- a/actix-web-codegen/tests/test_macro.rs +++ b/actix-web-codegen/tests/test_macro.rs @@ -2,11 +2,11 @@ use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; -use actix_web::{http, test, web::Path, App, HttpResponse, Responder, Error}; -use actix_web::dev::{Service, Transform, ServiceRequest, ServiceResponse}; +use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; +use actix_web::http::header::{HeaderName, HeaderValue}; +use actix_web::{http, test, web::Path, App, Error, HttpResponse, Responder}; use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace}; use futures_util::future; -use actix_web::http::header::{HeaderName, HeaderValue}; // Make sure that we can name function as 'config' #[get("/config")] @@ -119,7 +119,6 @@ where } fn call(&mut self, req: ServiceRequest) -> Self::Future { - let fut = self.service.call(req); Box::pin(async move { @@ -223,10 +222,7 @@ async fn test_auto_async() { #[actix_rt::test] async fn test_wrap() { - let srv = test::start(|| { - App::new() - .service(get_wrap) - }); + let srv = test::start(|| App::new().service(get_wrap)); let request = srv.request(http::Method::GET, srv.url("/test/wrap")); let response = request.send().await.unwrap(); diff --git a/awc/src/response.rs b/awc/src/response.rs index d1490cb98..8364aa556 100644 --- a/awc/src/response.rs +++ b/awc/src/response.rs @@ -402,9 +402,12 @@ mod tests { fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool { match err { - JsonPayloadError::Payload(PayloadError::Overflow) => - matches!(other, JsonPayloadError::Payload(PayloadError::Overflow)), - JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType), + JsonPayloadError::Payload(PayloadError::Overflow) => { + matches!(other, JsonPayloadError::Payload(PayloadError::Overflow)) + } + JsonPayloadError::ContentType => { + matches!(other, JsonPayloadError::ContentType) + } _ => false, } } diff --git a/src/middleware/normalize.rs b/src/middleware/normalize.rs index 3d5d30c80..56b1e6987 100644 --- a/src/middleware/normalize.rs +++ b/src/middleware/normalize.rs @@ -91,9 +91,9 @@ where // That approach fails when a trailing slash is added, // and a duplicate slash is removed, // since the length of the strings remains the same - // + // // For example, the path "/v1//s" will be normalized to "/v1/s/" - // Both of the paths have the same length, + // Both of the paths have the same length, // so the change can not be deduced from the length comparison if path != original_path { let mut parts = head.uri.clone().into_parts(); diff --git a/src/types/form.rs b/src/types/form.rs index d7db595ca..ea061d553 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -407,9 +407,15 @@ mod tests { fn eq(err: UrlencodedError, other: UrlencodedError) -> bool { match err { - UrlencodedError::Overflow { .. } => matches!(other, UrlencodedError::Overflow { .. }), - UrlencodedError::UnknownLength => matches!(other, UrlencodedError::UnknownLength), - UrlencodedError::ContentType => matches!(other, UrlencodedError::ContentType), + UrlencodedError::Overflow { .. } => { + matches!(other, UrlencodedError::Overflow { .. }) + } + UrlencodedError::UnknownLength => { + matches!(other, UrlencodedError::UnknownLength) + } + UrlencodedError::ContentType => { + matches!(other, UrlencodedError::ContentType) + } _ => false, } } diff --git a/src/types/json.rs b/src/types/json.rs index 1665ca95a..2401284bc 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -434,7 +434,9 @@ mod tests { fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool { match err { JsonPayloadError::Overflow => matches!(other, JsonPayloadError::Overflow), - JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType), + JsonPayloadError::ContentType => { + matches!(other, JsonPayloadError::ContentType) + } _ => false, } }