1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

Run rustfmt

This commit is contained in:
Yuki Okushi 2020-01-02 04:22:52 +09:00
parent 0eeda4c398
commit fe2553474e

View File

@ -1,8 +1,8 @@
use derive_more::Display; use derive_more::Display;
use std::fmt; use std::fmt;
use std::future::Future;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::pin::Pin; use std::pin::Pin;
use std::future::Future;
use std::task; use std::task;
use std::task::Poll; use std::task::Poll;
@ -15,7 +15,7 @@ use actix_web::dev::{HttpResponseBuilder, Payload};
use actix_web::error::{Error, PayloadError, ResponseError}; use actix_web::error::{Error, PayloadError, ResponseError};
use actix_web::http::header::{CONTENT_LENGTH, CONTENT_TYPE}; use actix_web::http::header::{CONTENT_LENGTH, CONTENT_TYPE};
use actix_web::{FromRequest, HttpMessage, HttpRequest, HttpResponse, Responder}; use actix_web::{FromRequest, HttpMessage, HttpRequest, HttpResponse, Responder};
use futures::future::{ready, LocalBoxFuture, FutureExt, Ready}; use futures::future::{ready, FutureExt, LocalBoxFuture, Ready};
use futures::StreamExt; use futures::StreamExt;
#[derive(Debug, Display)] #[derive(Debug, Display)]
@ -140,14 +140,16 @@ impl<T: Message + Default> Responder for ProtoBuf<T> {
fn respond_to(self, _: &HttpRequest) -> Self::Future { fn respond_to(self, _: &HttpRequest) -> Self::Future {
let mut buf = Vec::new(); let mut buf = Vec::new();
ready(self.0 ready(
self.0
.encode(&mut buf) .encode(&mut buf)
.map_err(|e| Error::from(ProtoBufPayloadError::Serialize(e))) .map_err(|e| Error::from(ProtoBufPayloadError::Serialize(e)))
.and_then(|()| { .and_then(|()| {
Ok(HttpResponse::Ok() Ok(HttpResponse::Ok()
.content_type("application/protobuf") .content_type("application/protobuf")
.body(buf)) .body(buf))
})) }),
)
} }
} }
@ -200,7 +202,10 @@ impl<T: Message + Default> ProtoBufMessage<T> {
impl<T: Message + Default + 'static> Future for ProtoBufMessage<T> { impl<T: Message + Default + 'static> Future for ProtoBufMessage<T> {
type Output = Result<T, ProtoBufPayloadError>; type Output = Result<T, ProtoBufPayloadError>;
fn poll(mut self: Pin<&mut Self>, task: &mut task::Context<'_>) -> Poll<Self::Output> { fn poll(
mut self: Pin<&mut Self>,
task: &mut task::Context<'_>,
) -> Poll<Self::Output> {
if let Some(ref mut fut) = self.fut { if let Some(ref mut fut) = self.fut {
return Pin::new(fut).poll(task); return Pin::new(fut).poll(task);
} }
@ -216,7 +221,10 @@ impl<T: Message + Default + 'static> Future for ProtoBufMessage<T> {
} }
} }
let mut stream = self.stream.take().expect("ProtoBufMessage could not be used second time"); let mut stream = self
.stream
.take()
.expect("ProtoBufMessage could not be used second time");
self.fut = Some( self.fut = Some(
async move { async move {
@ -258,8 +266,8 @@ impl ProtoBufResponseBuilder for HttpResponseBuilder {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use actix_web::test::TestRequest;
use actix_web::http::header; use actix_web::http::header;
use actix_web::test::TestRequest;
impl PartialEq for ProtoBufPayloadError { impl PartialEq for ProtoBufPayloadError {
fn eq(&self, other: &ProtoBufPayloadError) -> bool { fn eq(&self, other: &ProtoBufPayloadError) -> bool {
@ -305,22 +313,19 @@ mod tests {
let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl).await; let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl).await;
assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType); assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType);
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) =
header::CONTENT_TYPE, TestRequest::with_header(header::CONTENT_TYPE, "application/text")
"application/text", .to_http_parts();
).to_http_parts();
let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl).await; let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl).await;
assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType); assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType);
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) =
header::CONTENT_TYPE, TestRequest::with_header(header::CONTENT_TYPE, "application/protobuf")
"application/protobuf", .header(header::CONTENT_LENGTH, "10000")
).header( .to_http_parts();
header::CONTENT_LENGTH, let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl)
"10000", .limit(100)
).to_http_parts(); .await;
let protobuf =
ProtoBufMessage::<MyObject>::new(&req, &mut pl).limit(100).await;
assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::Overflow); assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::Overflow);
} }
} }