1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 23:42:56 +01:00

Fix clippy warnings (#40)

Add explicit `dyn`s

Remove let binding

Use +=

Return false

Derive Default for TcpConnector

Squash if/else

Remove unnecessary return keywords

Use is_empty()

Fix clippy attribute

Allow mut_from_ref
This commit is contained in:
Yuki Okushi 2019-08-17 05:15:51 +09:00 committed by GitHub
parent 7a18d9da26
commit aad013f559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 38 additions and 39 deletions

View File

@ -52,7 +52,7 @@ impl<T: Address> NewService for TcpConnectorFactory<T> {
} }
/// Tcp connector service /// Tcp connector service
#[derive(Debug)] #[derive(Default, Debug)]
pub struct TcpConnector<T>(PhantomData<T>); pub struct TcpConnector<T>(PhantomData<T>);
impl<T> TcpConnector<T> { impl<T> TcpConnector<T> {

View File

@ -113,17 +113,15 @@ impl<T: Address> Service for Resolver<T> {
fn call(&mut self, mut req: Connect<T>) -> Self::Future { fn call(&mut self, mut req: Connect<T>) -> Self::Future {
if req.addr.is_some() { if req.addr.is_some() {
Either::B(ok(req)) Either::B(ok(req))
} else if let Ok(ip) = req.host().parse() {
req.addr = Some(either::Either::Left(SocketAddr::new(ip, req.port())));
Either::B(ok(req))
} else { } else {
if let Ok(ip) = req.host().parse() { trace!("DNS resolver: resolving host {:?}", req.host());
req.addr = Some(either::Either::Left(SocketAddr::new(ip, req.port()))); if self.resolver.is_none() {
Either::B(ok(req)) self.resolver = Some(get_default_resolver());
} else {
trace!("DNS resolver: resolving host {:?}", req.host());
if self.resolver.is_none() {
self.resolver = Some(get_default_resolver());
}
Either::A(ResolverFuture::new(req, self.resolver.as_ref().unwrap()))
} }
Either::A(ResolverFuture::new(req, self.resolver.as_ref().unwrap()))
} }
} }
} }

View File

@ -44,7 +44,7 @@ where
framed: Framed<T, U>, framed: Framed<T, U>,
rx: Option<mpsc::UnboundedReceiver<FramedMessage<<U as Encoder>::Item>>>, rx: Option<mpsc::UnboundedReceiver<FramedMessage<<U as Encoder>::Item>>>,
inner: Cell<FramedDispatcherInner<<U as Encoder>::Item, S::Error>>, inner: Cell<FramedDispatcherInner<<U as Encoder>::Item, S::Error>>,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
} }
impl<St, S, T, U> FramedDispatcher<St, S, T, U> impl<St, S, T, U> FramedDispatcher<St, S, T, U>
@ -63,7 +63,7 @@ where
service: F, service: F,
rx: mpsc::UnboundedReceiver<FramedMessage<<U as Encoder>::Item>>, rx: mpsc::UnboundedReceiver<FramedMessage<<U as Encoder>::Item>>,
sink: Sink<<U as Encoder>::Item>, sink: Sink<<U as Encoder>::Item>,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
) -> Self { ) -> Self {
FramedDispatcher { FramedDispatcher {
framed, framed,

View File

@ -62,7 +62,7 @@ impl<St, Codec> Builder<St, Codec> {
pub struct ServiceBuilder<St, C, Io, Codec> { pub struct ServiceBuilder<St, C, Io, Codec> {
connect: C, connect: C,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
_t: PhantomData<(St, Io, Codec)>, _t: PhantomData<(St, Io, Codec)>,
} }
@ -113,7 +113,7 @@ where
pub struct NewServiceBuilder<St, C, Io, Codec> { pub struct NewServiceBuilder<St, C, Io, Codec> {
connect: C, connect: C,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
_t: PhantomData<(St, Io, Codec)>, _t: PhantomData<(St, Io, Codec)>,
} }
@ -170,7 +170,7 @@ where
pub(crate) struct FramedService<St, C, T, Io, Codec, Cfg> { pub(crate) struct FramedService<St, C, T, Io, Codec, Cfg> {
connect: C, connect: C,
handler: Rc<T>, handler: Rc<T>,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
_t: PhantomData<(St, Io, Codec, Cfg)>, _t: PhantomData<(St, Io, Codec, Cfg)>,
} }
@ -198,7 +198,7 @@ where
type Error = ServiceError<C::Error, Codec>; type Error = ServiceError<C::Error, Codec>;
type InitError = C::InitError; type InitError = C::InitError;
type Service = FramedServiceImpl<St, C::Service, T, Io, Codec>; type Service = FramedServiceImpl<St, C::Service, T, Io, Codec>;
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>; type Future = Box<dyn Future<Item = Self::Service, Error = Self::InitError>>;
fn new_service(&self, _: &Cfg) -> Self::Future { fn new_service(&self, _: &Cfg) -> Self::Future {
let handler = self.handler.clone(); let handler = self.handler.clone();
@ -221,7 +221,7 @@ where
pub struct FramedServiceImpl<St, C, T, Io, Codec> { pub struct FramedServiceImpl<St, C, T, Io, Codec> {
connect: C, connect: C,
handler: Rc<T>, handler: Rc<T>,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
_t: PhantomData<(St, Io, Codec)>, _t: PhantomData<(St, Io, Codec)>,
} }
@ -280,7 +280,7 @@ where
<Codec as Encoder>::Error: std::fmt::Debug, <Codec as Encoder>::Error: std::fmt::Debug,
{ {
inner: FramedServiceImplResponseInner<St, Io, Codec, C, T>, inner: FramedServiceImplResponseInner<St, Io, Codec, C, T>,
disconnect: Option<Rc<Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
} }
enum FramedServiceImplResponseInner<St, Io, Codec, C, T> enum FramedServiceImplResponseInner<St, Io, Codec, C, T>

View File

@ -16,15 +16,15 @@ use copyless::BoxHelper;
thread_local!( thread_local!(
static ADDR: RefCell<Option<Arbiter>> = RefCell::new(None); static ADDR: RefCell<Option<Arbiter>> = RefCell::new(None);
static RUNNING: Cell<bool> = Cell::new(false); static RUNNING: Cell<bool> = Cell::new(false);
static Q: RefCell<Vec<Box<Future<Item = (), Error = ()>>>> = RefCell::new(Vec::new()); static Q: RefCell<Vec<Box<dyn Future<Item = (), Error = ()>>>> = RefCell::new(Vec::new());
); );
pub(crate) static COUNT: AtomicUsize = AtomicUsize::new(0); pub(crate) static COUNT: AtomicUsize = AtomicUsize::new(0);
pub(crate) enum ArbiterCommand { pub(crate) enum ArbiterCommand {
Stop, Stop,
Execute(Box<Future<Item = (), Error = ()> + Send>), Execute(Box<dyn Future<Item = (), Error = ()> + Send>),
ExecuteFn(Box<FnExec>), ExecuteFn(Box<dyn FnExec>),
} }
impl fmt::Debug for ArbiterCommand { impl fmt::Debug for ArbiterCommand {
@ -180,7 +180,7 @@ impl Arbiter {
let _ = self let _ = self
.0 .0
.unbounded_send(ArbiterCommand::ExecuteFn(Box::new(move || { .unbounded_send(ArbiterCommand::ExecuteFn(Box::new(move || {
let _ = f(); f();
}))); })));
} }
@ -312,7 +312,7 @@ impl<F> FnExec for F
where where
F: FnOnce() + Send + 'static, F: FnOnce() + Send + 'static,
{ {
#[cfg_attr(feature = "cargo-clippy", allow(boxed_local))] #[allow(clippy::boxed_local)]
fn call_box(self: Box<Self>) { fn call_box(self: Box<Self>) {
(*self)() (*self)()
} }

View File

@ -40,7 +40,7 @@ impl Error for RunError {
fn description(&self) -> &str { fn description(&self) -> &str {
self.inner.description() self.inner.description()
} }
fn cause(&self) -> Option<&Error> { fn cause(&self) -> Option<&dyn Error> {
self.inner.source() self.inner.source()
} }
} }

View File

@ -4,7 +4,7 @@ use futures::{Async, Future, IntoFuture, Poll};
use crate::{NewService, Service}; use crate::{NewService, Service};
pub type BoxedService<Req, Res, Err> = Box< pub type BoxedService<Req, Res, Err> = Box<
Service< dyn Service<
Request = Req, Request = Req,
Response = Res, Response = Res,
Error = Err, Error = Err,
@ -13,7 +13,7 @@ pub type BoxedService<Req, Res, Err> = Box<
>; >;
pub type BoxedServiceResponse<Res, Err> = pub type BoxedServiceResponse<Res, Err> =
Either<FutureResult<Res, Err>, Box<Future<Item = Res, Error = Err>>>; Either<FutureResult<Res, Err>, Box<dyn Future<Item = Res, Error = Err>>>;
pub struct BoxedNewService<C, Req, Res, Err, InitErr>(Inner<C, Req, Res, Err, InitErr>); pub struct BoxedNewService<C, Req, Res, Err, InitErr>(Inner<C, Req, Res, Err, InitErr>);
@ -46,14 +46,14 @@ where
} }
type Inner<C, Req, Res, Err, InitErr> = Box< type Inner<C, Req, Res, Err, InitErr> = Box<
NewService< dyn NewService<
Config = C, Config = C,
Request = Req, Request = Req,
Response = Res, Response = Res,
Error = Err, Error = Err,
InitError = InitErr, InitError = InitErr,
Service = BoxedService<Req, Res, Err>, Service = BoxedService<Req, Res, Err>,
Future = Box<Future<Item = BoxedService<Req, Res, Err>, Error = InitErr>>, Future = Box<dyn Future<Item = BoxedService<Req, Res, Err>, Error = InitErr>>,
>, >,
>; >;
@ -70,7 +70,7 @@ where
type InitError = InitErr; type InitError = InitErr;
type Config = C; type Config = C;
type Service = BoxedService<Req, Res, Err>; type Service = BoxedService<Req, Res, Err>;
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>; type Future = Box<dyn Future<Item = Self::Service, Error = Self::InitError>>;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: &C) -> Self::Future {
self.0.new_service(cfg) self.0.new_service(cfg)
@ -99,7 +99,7 @@ where
type InitError = InitErr; type InitError = InitErr;
type Config = C; type Config = C;
type Service = BoxedService<Req, Res, Err>; type Service = BoxedService<Req, Res, Err>;
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>; type Future = Box<dyn Future<Item = Self::Service, Error = Self::InitError>>;
fn new_service(&self, cfg: &C) -> Self::Future { fn new_service(&self, cfg: &C) -> Self::Future {
Box::new( Box::new(
@ -133,7 +133,7 @@ where
type Error = Err; type Error = Err;
type Future = Either< type Future = Either<
FutureResult<Self::Response, Self::Error>, FutureResult<Self::Response, Self::Error>,
Box<Future<Item = Self::Response, Error = Self::Error>>, Box<dyn Future<Item = Self::Response, Error = Self::Error>>,
>; >;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {

View File

@ -34,6 +34,7 @@ impl<T> Cell<T> {
unsafe { &mut *self.inner.as_ref().get() } unsafe { &mut *self.inner.as_ref().get() }
} }
#[allow(clippy::mut_from_ref)]
pub(crate) unsafe fn get_mut_unsafe(&self) -> &mut T { pub(crate) unsafe fn get_mut_unsafe(&self) -> &mut T {
&mut *self.inner.as_ref().get() &mut *self.inner.as_ref().get()
} }

View File

@ -119,7 +119,7 @@ mod tests {
type Request = (); type Request = ();
type Response = (); type Response = ();
type Error = (); type Error = ();
type Future = Box<Future<Item = (), Error = ()>>; type Future = Box<dyn Future<Item = (), Error = ()>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(())) Ok(Async::Ready(()))

View File

@ -214,7 +214,7 @@ mod tests {
type Request = oneshot::Receiver<usize>; type Request = oneshot::Receiver<usize>;
type Response = usize; type Response = usize;
type Error = (); type Error = ();
type Future = Box<Future<Item = usize, Error = ()>>; type Future = Box<dyn Future<Item = usize, Error = ()>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(())) Ok(Async::Ready(()))

View File

@ -45,7 +45,7 @@ where
type Request = S; type Request = S;
type Response = (); type Response = ();
type Error = E; type Error = E;
type Future = Box<Future<Item = (), Error = E>>; type Future = Box<dyn Future<Item = (), Error = E>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(())) Ok(Async::Ready(()))

View File

@ -190,7 +190,7 @@ mod tests {
type Request = (); type Request = ();
type Response = (); type Response = ();
type Error = (); type Error = ();
type Future = Box<Future<Item = (), Error = ()>>; type Future = Box<dyn Future<Item = (), Error = ()>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(())) Ok(Async::Ready(()))

View File

@ -151,7 +151,7 @@ impl<'de, T: ResourcePath + 'de> Deserializer<'de> for PathDeserializer<'de, T>
where where
V: Visitor<'de>, V: Visitor<'de>,
{ {
if self.path.len() < 1 { if self.path.is_empty() {
Err(de::value::Error::custom( Err(de::value::Error::custom(
"expeceted at least one parameters", "expeceted at least one parameters",
)) ))

View File

@ -93,7 +93,7 @@ impl<T: ResourcePath> Path<T> {
#[inline] #[inline]
/// Skip first `n` chars in path /// Skip first `n` chars in path
pub fn skip(&mut self, n: u16) { pub fn skip(&mut self, n: u16) {
self.skip = self.skip + n; self.skip += n;
} }
pub(crate) fn add(&mut self, name: Rc<String>, value: PathItem) { pub(crate) fn add(&mut self, name: Rc<String>, value: PathItem) {

View File

@ -207,7 +207,7 @@ impl ResourceDef {
"Dynamic path match but not all segments found: {}", "Dynamic path match but not all segments found: {}",
name name
); );
false; return false;
} }
} }
} else { } else {
@ -279,7 +279,7 @@ impl ResourceDef {
"Dynamic path match but not all segments found: {}", "Dynamic path match but not all segments found: {}",
name name
); );
false; return false;
} }
} }
} else { } else {