Skip to content

Commit

Permalink
Fix clippy warnings (#505)
Browse files Browse the repository at this point in the history
Thought I might as well fix the clippy warnings. Feel free to 
close this if you don't want the git churn.
  • Loading branch information
davidpdrsn authored Jan 4, 2021
1 parent fdd66e5 commit 3bdaae9
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 19 deletions.
6 changes: 6 additions & 0 deletions tower/src/balance/p2c/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ impl<D, Req> MakeBalanceLayer<D, Req> {
}
}

impl<D, Req> Default for MakeBalanceLayer<D, Req> {
fn default() -> Self {
Self::new()
}
}

impl<S, Req> Layer<S> for MakeBalanceLayer<S, Req> {
type Service = MakeBalance<S, Req>;

Expand Down
5 changes: 5 additions & 0 deletions tower/src/balance/p2c/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D, Req> Balance<D, Req>
Expand Down
4 changes: 2 additions & 2 deletions tower/src/balance/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions tower/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ pub struct ServiceBuilder<L> {
layer: L,
}

impl Default for ServiceBuilder<Identity> {
fn default() -> Self {
Self::new()
}
}

impl ServiceBuilder<Identity> {
/// Create a new `ServiceBuilder`.
pub fn new() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion tower/src/hedge/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ where
return Poll::Ready(Ok(r.map_err(Into::into)?));
}
}
return Poll::Pending;
Poll::Pending
}
}
3 changes: 2 additions & 1 deletion tower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response, Error>`
Expand Down
1 change: 1 addition & 0 deletions tower/src/limit/rate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Limit the rate at which requests are processed.

mod layer;
#[allow(clippy::module_inception)]
mod rate;
mod service;

Expand Down
2 changes: 1 addition & 1 deletion tower/src/limit/rate/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<T> RateLimit<T> {
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.
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load_shed/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: (),
}
Expand Down
7 changes: 6 additions & 1 deletion tower/src/ready_cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)).
Expand Down
2 changes: 1 addition & 1 deletion tower/src/reconnect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/spawn_ready/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tower/src/timeout/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{error, fmt};

/// The timeout elapsed.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Elapsed(pub(super) ());

impl Elapsed {
Expand Down
4 changes: 2 additions & 2 deletions tower/tests/hedge/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ type Res = &'static str;
type Mock = tower_test::mock::Mock<Req, Res>;
type Handle = tower_test::mock::Handle<Req, Res>;

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;
Expand Down
8 changes: 1 addition & 7 deletions tower/tests/util/call_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions tower/tests/util/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "util")]
#![allow(clippy::type_complexity)]

mod call_all;
mod oneshot;
Expand Down

0 comments on commit 3bdaae9

Please sign in to comment.