Run rustfmt

This commit is contained in:
Yuki Okushi 2020-07-22 03:24:30 +09:00
parent 7498ef11f1
commit cb80a85454
No known key found for this signature in database
GPG Key ID: B0986C85C0E2DAA1
18 changed files with 108 additions and 113 deletions

View File

@ -952,9 +952,7 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_named_file_content_range_headers() { async fn test_named_file_content_range_headers() {
let srv = test::start(|| { let srv = test::start(|| App::new().service(Files::new("/", ".")));
App::new().service(Files::new("/", "."))
});
// Valid range header // Valid range header
let response = srv let response = srv
@ -979,9 +977,7 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_named_file_content_length_headers() { async fn test_named_file_content_length_headers() {
let srv = test::start(|| { let srv = test::start(|| App::new().service(Files::new("/", ".")));
App::new().service(Files::new("/", "."))
});
// Valid range header // Valid range header
let response = srv let response = srv
@ -1020,15 +1016,9 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_head_content_length_headers() { async fn test_head_content_length_headers() {
let srv = test::start(|| { let srv = test::start(|| App::new().service(Files::new("/", ".")));
App::new().service(Files::new("/", "."))
});
let response = srv let response = srv.head("/tests/test.binary").send().await.unwrap();
.head("/tests/test.binary")
.send()
.await
.unwrap();
let content_length = response let content_length = response
.headers() .headers()
@ -1097,12 +1087,10 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_named_file_content_encoding() { async fn test_named_file_content_encoding() {
let mut srv = test::init_service(App::new().wrap(Compress::default()).service( let mut srv = test::init_service(App::new().wrap(Compress::default()).service(
web::resource("/").to(|| { web::resource("/").to(|| async {
async { NamedFile::open("Cargo.toml")
NamedFile::open("Cargo.toml") .unwrap()
.unwrap() .set_content_encoding(header::ContentEncoding::Identity)
.set_content_encoding(header::ContentEncoding::Identity)
}
}), }),
)) ))
.await; .await;
@ -1119,12 +1107,10 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_named_file_content_encoding_gzip() { async fn test_named_file_content_encoding_gzip() {
let mut srv = test::init_service(App::new().wrap(Compress::default()).service( let mut srv = test::init_service(App::new().wrap(Compress::default()).service(
web::resource("/").to(|| { web::resource("/").to(|| async {
async { NamedFile::open("Cargo.toml")
NamedFile::open("Cargo.toml") .unwrap()
.unwrap() .set_content_encoding(header::ContentEncoding::Gzip)
.set_content_encoding(header::ContentEncoding::Gzip)
}
}), }),
)) ))
.await; .await;

View File

@ -22,9 +22,7 @@ pub enum BodySize {
impl BodySize { impl BodySize {
pub fn is_eof(&self) -> bool { pub fn is_eof(&self) -> bool {
match self { match self {
BodySize::None BodySize::None | BodySize::Empty | BodySize::Sized(0) => true,
| BodySize::Empty
| BodySize::Sized(0) => true,
_ => false, _ => false,
} }
} }
@ -470,9 +468,9 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use futures_util::stream;
use futures_util::future::poll_fn; use futures_util::future::poll_fn;
use futures_util::pin_mut; use futures_util::pin_mut;
use futures_util::stream;
impl Body { impl Body {
pub(crate) fn get_ref(&self) -> &[u8] { pub(crate) fn get_ref(&self) -> &[u8] {

View File

@ -37,7 +37,10 @@ where
trace!("Sending client request: {:?} {:?}", head, body.size()); trace!("Sending client request: {:?} {:?}", head, body.size());
let head_req = head.as_ref().method == Method::HEAD; let head_req = head.as_ref().method == Method::HEAD;
let length = body.size(); 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(()); let mut req = Request::new(());
*req.uri_mut() = head.as_ref().uri.clone(); *req.uri_mut() = head.as_ref().uri.clone();

View File

@ -69,10 +69,7 @@ where
inner: Rc::downgrade(&inner_rc), inner: Rc::downgrade(&inner_rc),
}); });
ConnectionPool( ConnectionPool(connector_rc, inner_rc)
connector_rc,
inner_rc,
)
} }
} }

View File

@ -303,55 +303,59 @@ where
} }
} }
}, },
ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => loop { ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => {
loop { loop {
if let Some(ref mut buffer) = this.buffer { loop {
match stream.poll_capacity(cx) { if let Some(ref mut buffer) = this.buffer {
Poll::Pending => return Poll::Pending, match stream.poll_capacity(cx) {
Poll::Ready(None) => return Poll::Ready(()), Poll::Pending => return Poll::Pending,
Poll::Ready(Some(Ok(cap))) => { Poll::Ready(None) => return Poll::Ready(()),
let len = buffer.len(); Poll::Ready(Some(Ok(cap))) => {
let bytes = buffer.split_to(std::cmp::min(cap, len)); 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); warn!("{:?}", e);
return Poll::Ready(()); 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))) => { } else {
warn!("{:?}", e); match body.as_mut().poll_next(cx) {
return Poll::Ready(()); Poll::Pending => return Poll::Pending,
} Poll::Ready(None) => {
} if let Err(e) = stream.send_data(Bytes::new(), true)
} else { {
match body.as_mut().poll_next(cx) { warn!("{:?}", e);
Poll::Pending => return Poll::Pending, }
Poll::Ready(None) => { return Poll::Ready(());
if let Err(e) = stream.send_data(Bytes::new(), true) { }
warn!("{:?}", e); 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(());
} }
} }
} }
} }
}, }
} }
} }
} }

View File

@ -1,5 +1,5 @@
use http::Method;
use http::header; use http::header;
use http::Method;
header! { header! {
/// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1) /// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1)

View File

@ -9,11 +9,13 @@
pub use self::accept_charset::AcceptCharset; pub use self::accept_charset::AcceptCharset;
//pub use self::accept_encoding::AcceptEncoding; //pub use self::accept_encoding::AcceptEncoding;
pub use self::accept_language::AcceptLanguage;
pub use self::accept::Accept; pub use self::accept::Accept;
pub use self::accept_language::AcceptLanguage;
pub use self::allow::Allow; pub use self::allow::Allow;
pub use self::cache_control::{CacheControl, CacheDirective}; 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_language::ContentLanguage;
pub use self::content_range::{ContentRange, ContentRangeSpec}; pub use self::content_range::{ContentRange, ContentRangeSpec};
pub use self::content_type::ContentType; pub use self::content_type::ContentType;
@ -47,7 +49,7 @@ macro_rules! __hyper__deref {
&mut self.0 &mut self.0
} }
} }
} };
} }
#[doc(hidden)] #[doc(hidden)]
@ -74,8 +76,8 @@ macro_rules! test_header {
($id:ident, $raw:expr) => { ($id:ident, $raw:expr) => {
#[test] #[test]
fn $id() { fn $id() {
use $crate::test;
use super::*; use super::*;
use $crate::test;
let raw = $raw; let raw = $raw;
let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect(); let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
@ -118,7 +120,7 @@ macro_rules! test_header {
// Test formatting // Test formatting
if typed.is_some() { if typed.is_some() {
let raw = &($raw)[..]; 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(); let mut joined = String::new();
joined.push_str(iter.next().unwrap()); joined.push_str(iter.next().unwrap());
for s in iter { for s in iter {
@ -128,7 +130,7 @@ macro_rules! test_header {
assert_eq!(format!("{}", typed.unwrap()), joined); assert_eq!(format!("{}", typed.unwrap()), joined);
} }
} }
} };
} }
#[macro_export] #[macro_export]
@ -330,11 +332,10 @@ macro_rules! header {
}; };
} }
mod accept_charset; mod accept_charset;
//mod accept_encoding; //mod accept_encoding;
mod accept_language;
mod accept; mod accept;
mod accept_language;
mod allow; mod allow;
mod cache_control; mod cache_control;
mod content_disposition; mod content_disposition;

View File

@ -274,9 +274,7 @@ async fn test_h2_head_empty() {
async fn test_h2_head_binary() { async fn test_h2_head_binary() {
let mut srv = test_server(move || { let mut srv = test_server(move || {
HttpService::build() HttpService::build()
.h2(|_| { .h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
ok::<_, ()>(Response::Ok().body(STR))
})
.openssl(ssl_acceptor()) .openssl(ssl_acceptor())
.map_err(|_| ()) .map_err(|_| ())
}) })

View File

@ -280,9 +280,7 @@ async fn test_h2_head_empty() {
async fn test_h2_head_binary() { async fn test_h2_head_binary() {
let mut srv = test_server(move || { let mut srv = test_server(move || {
HttpService::build() HttpService::build()
.h2(|_| { .h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
ok::<_, ()>(Response::Ok().body(STR))
})
.rustls(ssl_acceptor()) .rustls(ssl_acceptor())
}) })
.await; .await;

View File

@ -489,9 +489,7 @@ async fn test_h1_head_empty() {
async fn test_h1_head_binary() { async fn test_h1_head_binary() {
let mut srv = test_server(|| { let mut srv = test_server(|| {
HttpService::build() HttpService::build()
.h1(|_| { .h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
ok::<_, ()>(Response::Ok().body(STR))
})
.tcp() .tcp()
}) })
.await; .await;

View File

@ -30,8 +30,8 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Ws {
async fn test_simple() { async fn test_simple() {
let mut srv = test::start(|| { let mut srv = test::start(|| {
App::new().service(web::resource("/").to( App::new().service(web::resource("/").to(
|req: HttpRequest, stream: web::Payload| { |req: HttpRequest, stream: web::Payload| async move {
async move { ws::start(Ws, &req, stream) } ws::start(Ws, &req, stream)
}, },
)) ))
}); });

View File

@ -3,7 +3,7 @@ extern crate proc_macro;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2}; use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{format_ident, quote, ToTokens, TokenStreamExt}; 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 { enum ResourceType {
Async, Async,
@ -196,7 +196,12 @@ impl ToTokens for Route {
name, name,
guard, guard,
ast, ast,
args: Args { path, guards, wrappers }, args:
Args {
path,
guards,
wrappers,
},
resource_type, resource_type,
} = self; } = self;
let resource_name = name.to_string(); let resource_name = name.to_string();

View File

@ -2,11 +2,11 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use actix_web::{http, test, web::Path, App, HttpResponse, Responder, Error}; use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
use actix_web::dev::{Service, Transform, ServiceRequest, ServiceResponse}; 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 actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace};
use futures_util::future; use futures_util::future;
use actix_web::http::header::{HeaderName, HeaderValue};
// Make sure that we can name function as 'config' // Make sure that we can name function as 'config'
#[get("/config")] #[get("/config")]
@ -119,7 +119,6 @@ where
} }
fn call(&mut self, req: ServiceRequest) -> Self::Future { fn call(&mut self, req: ServiceRequest) -> Self::Future {
let fut = self.service.call(req); let fut = self.service.call(req);
Box::pin(async move { Box::pin(async move {
@ -223,10 +222,7 @@ async fn test_auto_async() {
#[actix_rt::test] #[actix_rt::test]
async fn test_wrap() { async fn test_wrap() {
let srv = test::start(|| { let srv = test::start(|| App::new().service(get_wrap));
App::new()
.service(get_wrap)
});
let request = srv.request(http::Method::GET, srv.url("/test/wrap")); let request = srv.request(http::Method::GET, srv.url("/test/wrap"));
let response = request.send().await.unwrap(); let response = request.send().await.unwrap();

View File

@ -402,9 +402,12 @@ mod tests {
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool { fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
match err { match err {
JsonPayloadError::Payload(PayloadError::Overflow) => JsonPayloadError::Payload(PayloadError::Overflow) => {
matches!(other, JsonPayloadError::Payload(PayloadError::Overflow)), matches!(other, JsonPayloadError::Payload(PayloadError::Overflow))
JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType), }
JsonPayloadError::ContentType => {
matches!(other, JsonPayloadError::ContentType)
}
_ => false, _ => false,
} }
} }

View File

@ -407,9 +407,15 @@ mod tests {
fn eq(err: UrlencodedError, other: UrlencodedError) -> bool { fn eq(err: UrlencodedError, other: UrlencodedError) -> bool {
match err { match err {
UrlencodedError::Overflow { .. } => matches!(other, UrlencodedError::Overflow { .. }), UrlencodedError::Overflow { .. } => {
UrlencodedError::UnknownLength => matches!(other, UrlencodedError::UnknownLength), matches!(other, UrlencodedError::Overflow { .. })
UrlencodedError::ContentType => matches!(other, UrlencodedError::ContentType), }
UrlencodedError::UnknownLength => {
matches!(other, UrlencodedError::UnknownLength)
}
UrlencodedError::ContentType => {
matches!(other, UrlencodedError::ContentType)
}
_ => false, _ => false,
} }
} }

View File

@ -434,7 +434,9 @@ mod tests {
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool { fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
match err { match err {
JsonPayloadError::Overflow => matches!(other, JsonPayloadError::Overflow), JsonPayloadError::Overflow => matches!(other, JsonPayloadError::Overflow),
JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType), JsonPayloadError::ContentType => {
matches!(other, JsonPayloadError::ContentType)
}
_ => false, _ => false,
} }
} }