style(lib): run rustfmt and enforce in CI

This commit is contained in:
Sean McArthur
2019-12-05 13:30:53 -08:00
parent b0060f277e
commit 0dc89680cd
69 changed files with 2982 additions and 2499 deletions

View File

@@ -1,7 +1,7 @@
use std::error::Error as StdError;
use crate::body::Payload;
use crate::common::{Future, Poll, task};
use crate::common::{task, Future, Poll};
use crate::{Request, Response};
/// An asynchronous function from `Request` to `Response`.
@@ -17,7 +17,7 @@ pub trait HttpService<ReqBody>: sealed::Sealed<ReqBody> {
type Error: Into<Box<dyn StdError + Send + Sync>>;
/// The `Future` returned by this `Service`.
type Future: Future<Output=Result<Response<Self::ResBody>, Self::Error>>;
type Future: Future<Output = Result<Response<Self::ResBody>, Self::Error>>;
#[doc(hidden)]
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;
@@ -27,7 +27,7 @@ pub trait HttpService<ReqBody>: sealed::Sealed<ReqBody> {
}
impl<T, B1, B2> HttpService<B1> for T
where
where
T: tower_service::Service<Request<B1>, Response = Response<B2>>,
B2: Payload,
T::Error: Into<Box<dyn StdError + Send + Sync>>,
@@ -46,13 +46,13 @@ where
}
}
impl<T, B1, B2> sealed::Sealed<B1> for T
where
impl<T, B1, B2> sealed::Sealed<B1> for T
where
T: tower_service::Service<Request<B1>, Response = Response<B2>>,
B2: Payload,
{}
{
}
mod sealed {
pub trait Sealed<T> {}
}

View File

@@ -3,9 +3,9 @@ use std::fmt;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::body::Payload;
use crate::common::{Future, Poll, task};
use super::{HttpService, Service};
use crate::body::Payload;
use crate::common::{task, Future, Poll};
// The same "trait alias" as tower::MakeConnection, but inlined to reduce
// dependencies.
@@ -44,13 +44,9 @@ where
pub trait MakeServiceRef<Target, ReqBody>: self::sealed::Sealed<(Target, ReqBody)> {
type ResBody: Payload;
type Error: Into<Box<dyn StdError + Send + Sync>>;
type Service: HttpService<
ReqBody,
ResBody=Self::ResBody,
Error=Self::Error,
>;
type Service: HttpService<ReqBody, ResBody = Self::ResBody, Error = Self::Error>;
type MakeError: Into<Box<dyn StdError + Send + Sync>>;
type Future: Future<Output=Result<Self::Service, Self::MakeError>>;
type Future: Future<Output = Result<Self::Service, Self::MakeError>>;
// Acting like a #[non_exhaustive] for associated types of this trait.
//
@@ -70,11 +66,11 @@ pub trait MakeServiceRef<Target, ReqBody>: self::sealed::Sealed<(Target, ReqBody
impl<T, Target, E, ME, S, F, IB, OB> MakeServiceRef<Target, IB> for T
where
T: for<'a> Service<&'a Target, Error=ME, Response=S, Future=F>,
T: for<'a> Service<&'a Target, Error = ME, Response = S, Future = F>,
E: Into<Box<dyn StdError + Send + Sync>>,
ME: Into<Box<dyn StdError + Send + Sync>>,
S: HttpService<IB, ResBody=OB, Error=E>,
F: Future<Output=Result<S, ME>>,
S: HttpService<IB, ResBody = OB, Error = E>,
F: Future<Output = Result<S, ME>>,
IB: Payload,
OB: Payload,
{
@@ -145,9 +141,7 @@ where
F: FnMut(&Target) -> Ret,
Ret: Future,
{
MakeServiceFn {
f,
}
MakeServiceFn { f }
}
// Not exported from crate as this will likely be replaced with `impl Service`.
@@ -158,7 +152,7 @@ pub struct MakeServiceFn<F> {
impl<'t, F, Ret, Target, Svc, MkErr> Service<&'t Target> for MakeServiceFn<F>
where
F: FnMut(&Target) -> Ret,
Ret: Future<Output=Result<Svc, MkErr>>,
Ret: Future<Output = Result<Svc, MkErr>>,
MkErr: Into<Box<dyn StdError + Send + Sync>>,
{
type Error = MkErr;
@@ -176,8 +170,7 @@ where
impl<F> fmt::Debug for MakeServiceFn<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MakeServiceFn")
.finish()
f.debug_struct("MakeServiceFn").finish()
}
}

View File

@@ -41,10 +41,9 @@ mod make;
mod oneshot;
mod util;
pub(crate) use self::make::{MakeConnection, MakeServiceRef};
pub(crate) use self::http::HttpService;
pub(crate) use self::make::{MakeConnection, MakeServiceRef};
pub(crate) use self::oneshot::{oneshot, Oneshot};
pub use self::make::make_service_fn;
pub use self::util::service_fn;

View File

@@ -1,11 +1,11 @@
// TODO: Eventually to be replaced with tower_util::Oneshot.
use std::mem;
use std::marker::Unpin;
use std::mem;
use tower_service::Service;
use crate::common::{Future, Pin, Poll, task};
use crate::common::{task, Future, Pin, Poll};
pub(crate) fn oneshot<S, Req>(svc: S, req: Req) -> Oneshot<S, Req>
where
@@ -35,7 +35,8 @@ impl<S, Req> Unpin for Oneshot<S, Req>
where
S: Service<Req>,
S::Future: Unpin,
{}
{
}
impl<S, Req> Future for Oneshot<S, Req>
where
@@ -52,17 +53,17 @@ where
State::NotReady(ref mut svc, _) => {
ready!(svc.poll_ready(cx))?;
// fallthrough out of the match's borrow
},
}
State::Called(ref mut fut) => {
return unsafe { Pin::new_unchecked(fut) }.poll(cx);
},
}
State::Tmp => unreachable!(),
}
match mem::replace(&mut me.state, State::Tmp) {
State::NotReady(mut svc, req) => {
me.state = State::Called(svc.call(req));
},
}
_ => unreachable!(),
}
}

View File

@@ -3,7 +3,7 @@ use std::fmt;
use std::marker::PhantomData;
use crate::body::Payload;
use crate::common::{Future, Poll, task};
use crate::common::{task, Future, Poll};
use crate::{Request, Response};
/// Create a `Service` from a function.
@@ -41,11 +41,12 @@ pub struct ServiceFn<F, R> {
_req: PhantomData<fn(R)>,
}
impl<F, ReqBody, Ret, ResBody, E> tower_service::Service<crate::Request<ReqBody>> for ServiceFn<F, ReqBody>
impl<F, ReqBody, Ret, ResBody, E> tower_service::Service<crate::Request<ReqBody>>
for ServiceFn<F, ReqBody>
where
F: FnMut(Request<ReqBody>) -> Ret,
ReqBody: Payload,
Ret: Future<Output=Result<Response<ResBody>, E>>,
Ret: Future<Output = Result<Response<ResBody>, E>>,
E: Into<Box<dyn StdError + Send + Sync>>,
ResBody: Payload,
{
@@ -64,7 +65,6 @@ where
impl<F, R> fmt::Debug for ServiceFn<F, R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("impl Service")
.finish()
f.debug_struct("impl Service").finish()
}
}