diff --git a/tower/src/balance/p2c/layer.rs b/tower/src/balance/p2c/layer.rs index cca32e643..6dbfd9763 100644 --- a/tower/src/balance/p2c/layer.rs +++ b/tower/src/balance/p2c/layer.rs @@ -32,6 +32,12 @@ impl MakeBalanceLayer { } } +impl Default for MakeBalanceLayer { + fn default() -> Self { + Self::new() + } +} + impl Layer for MakeBalanceLayer { type Service = MakeBalance; diff --git a/tower/src/balance/p2c/service.rs b/tower/src/balance/p2c/service.rs index 97cccb919..8554d2d86 100644 --- a/tower/src/balance/p2c/service.rs +++ b/tower/src/balance/p2c/service.rs @@ -107,6 +107,11 @@ where pub fn len(&self) -> usize { self.services.len() } + + /// Returns whether or not the balancer is empty. + pub fn is_empty(&self) -> bool { + self.services.is_empty() + } } impl Balance diff --git a/tower/src/balance/pool/mod.rs b/tower/src/balance/pool/mod.rs index 799aaf849..57ba6134f 100644 --- a/tower/src/balance/pool/mod.rs +++ b/tower/src/balance/pool/mod.rs @@ -98,7 +98,7 @@ where ); } - if this.services.len() == 0 && this.making.is_none() { + if this.services.is_empty() && this.making.is_none() { let _ = ready!(this.maker.poll_ready(cx))?; tracing::trace!("construct initial pool connection"); this.making @@ -367,7 +367,7 @@ where if let Poll::Ready(()) = self.balance.poll_ready(cx)? { // services was ready -- there are enough services // update ewma with a 0 sample - self.ewma = (1.0 - self.options.alpha) * self.ewma; + self.ewma *= 1.0 - self.options.alpha; let discover = self.balance.discover_mut().as_mut().project(); if self.ewma < self.options.low { diff --git a/tower/src/builder/mod.rs b/tower/src/builder/mod.rs index 342db9602..3efd091e7 100644 --- a/tower/src/builder/mod.rs +++ b/tower/src/builder/mod.rs @@ -106,6 +106,12 @@ pub struct ServiceBuilder { layer: L, } +impl Default for ServiceBuilder { + fn default() -> Self { + Self::new() + } +} + impl ServiceBuilder { /// Create a new `ServiceBuilder`. pub fn new() -> Self { diff --git a/tower/src/hedge/select.rs b/tower/src/hedge/select.rs index 31a7f3c7e..2841d59cb 100644 --- a/tower/src/hedge/select.rs +++ b/tower/src/hedge/select.rs @@ -99,6 +99,6 @@ where return Poll::Ready(Ok(r.map_err(Into::into)?)); } } - return Poll::Pending; + Poll::Pending } } diff --git a/tower/src/lib.rs b/tower/src/lib.rs index 7b1af6364..4ef3554cd 100644 --- a/tower/src/lib.rs +++ b/tower/src/lib.rs @@ -5,7 +5,8 @@ rust_2018_idioms, unreachable_pub )] -#![allow(elided_lifetimes_in_paths)] +#![allow(elided_lifetimes_in_paths, clippy::type_complexity)] +#![cfg_attr(test, allow(clippy::float_cmp))] #![cfg_attr(docsrs, feature(doc_cfg))] //! `async fn(Request) -> Result` diff --git a/tower/src/limit/rate/mod.rs b/tower/src/limit/rate/mod.rs index e209b6f54..52b179b8c 100644 --- a/tower/src/limit/rate/mod.rs +++ b/tower/src/limit/rate/mod.rs @@ -1,6 +1,7 @@ //! Limit the rate at which requests are processed. mod layer; +#[allow(clippy::module_inception)] mod rate; mod service; diff --git a/tower/src/limit/rate/service.rs b/tower/src/limit/rate/service.rs index d59276134..550c92d8a 100644 --- a/tower/src/limit/rate/service.rs +++ b/tower/src/limit/rate/service.rs @@ -37,7 +37,7 @@ impl RateLimit { RateLimit { inner, rate, - state: state, + state, // The sleep won't actually be used with this duration, but // we create it eagerly so that we can reset it in place rather than // `Box::pin`ning a new `Sleep` every time we need one. diff --git a/tower/src/load_shed/layer.rs b/tower/src/load_shed/layer.rs index 96aa2fd71..72af6a58c 100644 --- a/tower/src/load_shed/layer.rs +++ b/tower/src/load_shed/layer.rs @@ -4,7 +4,7 @@ use tower_layer::Layer; use super::LoadShed; /// A `tower-layer` to wrap services in `LoadShed` middleware. -#[derive(Clone)] +#[derive(Clone, Default)] pub struct LoadShedLayer { _p: (), } diff --git a/tower/src/ready_cache/cache.rs b/tower/src/ready_cache/cache.rs index f1fb692a0..33b0a0439 100644 --- a/tower/src/ready_cache/cache.rs +++ b/tower/src/ready_cache/cache.rs @@ -121,6 +121,11 @@ where self.ready_len() + self.pending_len() } + /// Returns whether or not there are any services in the cache. + pub fn is_empty(&self) -> bool { + self.ready.is_empty() && self.pending.is_empty() + } + /// Returns the number of services in the ready set. pub fn ready_len(&self) -> usize { self.ready.len() @@ -263,7 +268,7 @@ where } Poll::Ready(Some(Err(PendingError::Inner(key, e)))) => { let cancel_tx = self.pending_cancel_txs.swap_remove(&key); - if let Some(_) = cancel_tx { + if cancel_tx.is_some() { return Err(error::Failed(key, e.into())).into(); } else { // See comment for the same clause under Ready(Some(Ok)). diff --git a/tower/src/reconnect/mod.rs b/tower/src/reconnect/mod.rs index d64b120e9..f477e8820 100644 --- a/tower/src/reconnect/mod.rs +++ b/tower/src/reconnect/mod.rs @@ -111,7 +111,7 @@ where Poll::Ready(Err(e)) => { trace!("poll_ready; error"); self.state = State::Idle; - self.error = Some(e.into()); + self.error = Some(e); break; } } diff --git a/tower/src/spawn_ready/layer.rs b/tower/src/spawn_ready/layer.rs index 5e1185d3a..390708155 100644 --- a/tower/src/spawn_ready/layer.rs +++ b/tower/src/spawn_ready/layer.rs @@ -2,7 +2,7 @@ use super::MakeSpawnReady; use tower_layer::Layer; /// Spawns tasks to drive its inner service to readiness. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct SpawnReadyLayer; impl SpawnReadyLayer { diff --git a/tower/src/timeout/error.rs b/tower/src/timeout/error.rs index ee6e0cc64..223cada68 100644 --- a/tower/src/timeout/error.rs +++ b/tower/src/timeout/error.rs @@ -3,7 +3,7 @@ use std::{error, fmt}; /// The timeout elapsed. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Elapsed(pub(super) ()); impl Elapsed { diff --git a/tower/tests/hedge/main.rs b/tower/tests/hedge/main.rs index 3008a64e4..d4082ca2a 100644 --- a/tower/tests/hedge/main.rs +++ b/tower/tests/hedge/main.rs @@ -146,8 +146,8 @@ type Res = &'static str; type Mock = tower_test::mock::Mock; type Handle = tower_test::mock::Handle; -static NOT_RETRYABLE: &'static str = "NOT_RETRYABLE"; -static NOT_CLONABLE: &'static str = "NOT_CLONABLE"; +static NOT_RETRYABLE: &str = "NOT_RETRYABLE"; +static NOT_CLONABLE: &str = "NOT_CLONABLE"; #[derive(Clone)] struct TestPolicy; diff --git a/tower/tests/util/call_all.rs b/tower/tests/util/call_all.rs index 373b3aea4..c5d8fa0a0 100644 --- a/tower/tests/util/call_all.rs +++ b/tower/tests/util/call_all.rs @@ -102,13 +102,7 @@ fn ordered() { assert_eq!(count.get(), 4); // We should also be able to recover the wrapped Service. - assert_eq!( - ca.take_service(), - Srv { - count: count.clone(), - admit - } - ); + assert_eq!(ca.take_service(), Srv { count, admit }); } #[tokio::test(flavor = "current_thread")] diff --git a/tower/tests/util/main.rs b/tower/tests/util/main.rs index e80bb0f2c..18b7813ff 100644 --- a/tower/tests/util/main.rs +++ b/tower/tests/util/main.rs @@ -1,4 +1,5 @@ #![cfg(feature = "util")] +#![allow(clippy::type_complexity)] mod call_all; mod oneshot;