diff --git a/tower-balance/Cargo.toml b/tower-balance/Cargo.toml index fae52a0..4c6d436 100644 --- a/tower-balance/Cargo.toml +++ b/tower-balance/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-balance" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-balance/examples/demo.rs b/tower-balance/examples/demo.rs index 89ca6ad..eb47f6f 100644 --- a/tower-balance/examples/demo.rs +++ b/tower-balance/examples/demo.rs @@ -1,30 +1,15 @@ //! Exercises load balancers with mocked services. -extern crate env_logger; -extern crate futures; -extern crate hdrsample; -extern crate log; -extern crate rand; -extern crate tokio; -extern crate tower; -extern crate tower_balance; -extern crate tower_buffer; -extern crate tower_discover; -extern crate tower_limit; -extern crate tower_service; -extern crate tower_util; - +use env_logger; use futures::{future, stream, Future, Stream}; use hdrsample::Histogram; -use rand::Rng; +use rand::{self, Rng}; use std::time::{Duration, Instant}; use tokio::{runtime, timer}; -use tower::ServiceExt; +use tower::{ + discover::Discover, limit::concurrency::ConcurrencyLimit, util::ServiceFn, Service, ServiceExt, +}; use tower_balance as lb; -use tower_discover::Discover; -use tower_limit::concurrency::ConcurrencyLimit; -use tower_service::Service; -use tower_util::ServiceFn; const REQUESTS: usize = 50_000; const CONCURRENCY: usize = 500; @@ -125,7 +110,7 @@ fn main() { rt.shutdown_on_idle().wait().unwrap(); } -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; fn gen_disco() -> impl Discover< Key = usize, diff --git a/tower-balance/src/choose/mod.rs b/tower-balance/src/choose/mod.rs index 60e76dd..7eda391 100644 --- a/tower-balance/src/choose/mod.rs +++ b/tower-balance/src/choose/mod.rs @@ -3,8 +3,7 @@ use indexmap::IndexMap; mod p2c; mod round_robin; -pub use self::p2c::PowerOfTwoChoices; -pub use self::round_robin::RoundRobin; +pub use self::{p2c::PowerOfTwoChoices, round_robin::RoundRobin}; /// A strategy for choosing nodes. // TODO hide `K` @@ -32,15 +31,15 @@ pub struct TooFew; /// Holds two or more services. // TODO hide `K` -pub struct Replicas<'a, K: 'a, S: 'a>(&'a IndexMap); +pub struct Replicas<'a, K, S>(&'a IndexMap); -impl<'a, K: 'a, S: 'a> Replicas<'a, K, S> { +impl Replicas<'_, K, S> { pub fn len(&self) -> usize { self.0.len() } } -impl<'a, K: 'a, S: 'a> ::std::ops::Index for Replicas<'a, K, S> { +impl ::std::ops::Index for Replicas<'_, K, S> { type Output = S; fn index(&self, idx: usize) -> &Self::Output { diff --git a/tower-balance/src/choose/p2c.rs b/tower-balance/src/choose/p2c.rs index e117431..89a26a1 100644 --- a/tower-balance/src/choose/p2c.rs +++ b/tower-balance/src/choose/p2c.rs @@ -1,7 +1,10 @@ +use log::trace; use rand::{rngs::SmallRng, FromEntropy, Rng}; -use choose::{Choose, Replicas}; -use Load; +use crate::{ + choose::{Choose, Replicas}, + Load, +}; /// Chooses nodes using the [Power of Two Choices][p2c]. /// diff --git a/tower-balance/src/choose/round_robin.rs b/tower-balance/src/choose/round_robin.rs index bc77c19..6eeef67 100644 --- a/tower-balance/src/choose/round_robin.rs +++ b/tower-balance/src/choose/round_robin.rs @@ -1,4 +1,4 @@ -use choose::{Choose, Replicas}; +use crate::choose::{Choose, Replicas}; /// Chooses nodes sequentially. /// diff --git a/tower-balance/src/lib.rs b/tower-balance/src/lib.rs index 82448c8..86b9960 100644 --- a/tower-balance/src/lib.rs +++ b/tower-balance/src/lib.rs @@ -1,19 +1,11 @@ -#[macro_use] -extern crate futures; -#[macro_use] -extern crate log; -extern crate indexmap; -extern crate rand; -extern crate tokio_timer; -extern crate tower_discover; -extern crate tower_service; -extern crate tower_util; - +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] #[cfg(test)] extern crate quickcheck; use futures::{Async, Poll}; use indexmap::IndexMap; +use log::{debug, trace}; use rand::{rngs::SmallRng, SeedableRng}; use std::fmt; use tower_discover::Discover; @@ -28,13 +20,16 @@ pub mod pool; #[cfg(test)] mod test; -pub use self::choose::Choose; -pub use self::load::weight::{HasWeight, Weight, Weighted, WithWeighted}; -pub use self::load::Load; -pub use self::pool::Pool; +pub use self::{ + choose::Choose, + load::{ + weight::{HasWeight, Weight, Weighted, WithWeighted}, + Load, + }, + pool::Pool, +}; -use self::error::Error; -use self::future::ResponseFuture; +use self::{error::Error, future::ResponseFuture}; /// Balances requests across a set of inner services. #[derive(Debug)] @@ -168,7 +163,7 @@ where self.discover.poll().map_err(|e| error::Balance(e.into()))? { match change { - Insert(key, mut svc) => { + Insert(key, svc) => { // If the `Insert`ed service is a duplicate of a service already // in the ready list, remove the ready service first. The new // service will then be inserted into the not-ready list. diff --git a/tower-balance/src/load/constant.rs b/tower-balance/src/load/constant.rs index 37967a7..4860b6f 100644 --- a/tower-balance/src/load/constant.rs +++ b/tower-balance/src/load/constant.rs @@ -1,8 +1,8 @@ -use futures::{Async, Poll}; +use futures::{try_ready, Async, Poll}; use tower_discover::{Change, Discover}; use tower_service::Service; -use Load; +use crate::Load; /// Wraps a type so that `Load::load` returns a constant value. pub struct Constant { diff --git a/tower-balance/src/load/instrument.rs b/tower-balance/src/load/instrument.rs index 282071d..4c8d00a 100644 --- a/tower-balance/src/load/instrument.rs +++ b/tower-balance/src/load/instrument.rs @@ -1,4 +1,4 @@ -use futures::{Future, Poll}; +use futures::{try_ready, Future, Poll}; /// Attaches `I`-typed instruments to `V` typed values. /// diff --git a/tower-balance/src/load/mod.rs b/tower-balance/src/load/mod.rs index f90a3b1..233a015 100644 --- a/tower-balance/src/load/mod.rs +++ b/tower-balance/src/load/mod.rs @@ -4,10 +4,12 @@ pub mod peak_ewma; pub mod pending_requests; pub(crate) mod weight; -pub use self::constant::Constant; -pub use self::instrument::{Instrument, InstrumentFuture, NoInstrument}; -pub use self::peak_ewma::{PeakEwma, WithPeakEwma}; -pub use self::pending_requests::{PendingRequests, WithPendingRequests}; +pub use self::{ + constant::Constant, + instrument::{Instrument, InstrumentFuture, NoInstrument}, + peak_ewma::{PeakEwma, WithPeakEwma}, + pending_requests::{PendingRequests, WithPendingRequests}, +}; /// Exposes a load metric. /// diff --git a/tower-balance/src/load/peak_ewma.rs b/tower-balance/src/load/peak_ewma.rs index 0317804..d1a3735 100644 --- a/tower-balance/src/load/peak_ewma.rs +++ b/tower-balance/src/load/peak_ewma.rs @@ -1,14 +1,17 @@ -use futures::{Async, Poll}; -use std::ops; -use std::sync::{Arc, Mutex}; -use std::time::{Duration, Instant}; +use futures::{try_ready, Async, Poll}; +use log::trace; +use std::{ + ops, + sync::{Arc, Mutex}, + time::{Duration, Instant}, +}; use tokio_timer::clock; use tower_discover::{Change, Discover}; use tower_service::Service; use super::{Instrument, InstrumentFuture, NoInstrument}; -use {HasWeight, Load, Weight}; +use crate::{HasWeight, Load, Weight}; /// Wraps an `S`-typed Service with Peak-EWMA load measurement. /// @@ -307,14 +310,13 @@ fn nanos(d: Duration) -> f64 { #[cfg(test)] mod tests { - extern crate tokio_executor; - extern crate tokio_timer; - - use self::tokio_executor::enter; - use self::tokio_timer::clock; use futures::{future, Future, Poll}; - use std::sync::{Arc, Mutex}; - use std::time::{Duration, Instant}; + use std::{ + sync::{Arc, Mutex}, + time::{Duration, Instant}, + }; + use tokio_executor::enter; + use tokio_timer::clock; use super::*; diff --git a/tower-balance/src/load/pending_requests.rs b/tower-balance/src/load/pending_requests.rs index 260cd96..0325c4d 100644 --- a/tower-balance/src/load/pending_requests.rs +++ b/tower-balance/src/load/pending_requests.rs @@ -1,11 +1,10 @@ -use futures::{Async, Poll}; -use std::ops; -use std::sync::Arc; +use futures::{try_ready, Async, Poll}; +use std::{ops, sync::Arc}; use tower_discover::{Change, Discover}; use tower_service::Service; use super::{Instrument, InstrumentFuture, NoInstrument}; -use {HasWeight, Load, Weight}; +use crate::{HasWeight, Load, Weight}; /// Expresses load based on the number of currently-pending requests. #[derive(Debug)] diff --git a/tower-balance/src/load/weight.rs b/tower-balance/src/load/weight.rs index b65e9c3..7ae31e3 100644 --- a/tower-balance/src/load/weight.rs +++ b/tower-balance/src/load/weight.rs @@ -1,9 +1,9 @@ -use futures::{Async, Poll}; +use futures::{try_ready, Async, Poll}; use std::ops; use tower_discover::{Change, Discover}; use tower_service::Service; -use Load; +use crate::Load; /// A weight on [0.0, ∞]. /// diff --git a/tower-balance/src/pool.rs b/tower-balance/src/pool.rs index f85c46a..c86f811 100644 --- a/tower-balance/src/pool.rs +++ b/tower-balance/src/pool.rs @@ -15,7 +15,7 @@ #![deny(missing_docs)] use super::{Balance, Choose}; -use futures::{Async, Future, Poll}; +use futures::{try_ready, Async, Future, Poll}; use tower_discover::{Change, Discover}; use tower_service::Service; use tower_util::MakeService; diff --git a/tower-buffer/Cargo.toml b/tower-buffer/Cargo.toml index d16e121..f3ae007 100644 --- a/tower-buffer/Cargo.toml +++ b/tower-buffer/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-buffer" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1.25" @@ -12,4 +13,5 @@ tokio-executor = "0.1.7" tokio-sync = "0.1.0" [dev-dependencies] +tower = { version = "0.1", path = "../tower" } tower-test = { version = "0.1", path = "../tower-test" } diff --git a/tower-buffer/src/error.rs b/tower-buffer/src/error.rs index 0fbeb77..de4dac2 100644 --- a/tower-buffer/src/error.rs +++ b/tower-buffer/src/error.rs @@ -1,7 +1,6 @@ //! Error types -use std::fmt; -use std::sync::Arc; +use std::{fmt, sync::Arc}; /// An error produced by a `Service` wrapped by a `Buffer` #[derive(Debug)] @@ -22,7 +21,7 @@ pub struct SpawnError { } /// Errors produced by `Buffer`. -pub(crate) type Error = Box<::std::error::Error + Send + Sync>; +pub(crate) type Error = Box; // ===== impl ServiceError ===== diff --git a/tower-buffer/src/future.rs b/tower-buffer/src/future.rs index 004119d..42af244 100644 --- a/tower-buffer/src/future.rs +++ b/tower-buffer/src/future.rs @@ -1,8 +1,10 @@ //! Future types -use error::{Closed, Error}; +use crate::{ + error::{Closed, Error}, + message, +}; use futures::{Async, Future, Poll}; -use message; /// Future eventually completed with the response to the original request. pub struct ResponseFuture { diff --git a/tower-buffer/src/lib.rs b/tower-buffer/src/lib.rs index ba11b2c..30165b3 100644 --- a/tower-buffer/src/lib.rs +++ b/tower-buffer/src/lib.rs @@ -1,3 +1,6 @@ +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] + //! Buffer requests when the inner service is out of capacity. //! //! Buffering works by spawning a new task that is dedicated to pulling requests @@ -5,29 +8,18 @@ //! buffer and a dedicated task, the `Buffer` layer in front of the service can //! be `Clone` even if the inner service is not. -#[macro_use] -extern crate futures; -extern crate tokio_executor; -extern crate tokio_sync; -extern crate tower_layer; -extern crate tower_service; - pub mod error; pub mod future; mod message; mod worker; -pub use worker::WorkerExecutor; +pub use crate::worker::WorkerExecutor; -use error::Error; -use future::ResponseFuture; -use message::Message; -use worker::Worker; +use crate::{error::Error, future::ResponseFuture, message::Message, worker::Worker}; use futures::Poll; use tokio_executor::DefaultExecutor; -use tokio_sync::mpsc; -use tokio_sync::oneshot; +use tokio_sync::{mpsc, oneshot}; use tower_layer::Layer; use tower_service::Service; diff --git a/tower-buffer/src/message.rs b/tower-buffer/src/message.rs index 342ad22..d7717c8 100644 --- a/tower-buffer/src/message.rs +++ b/tower-buffer/src/message.rs @@ -1,4 +1,4 @@ -use error::ServiceError; +use crate::error::ServiceError; use tokio_sync::oneshot; /// Message sent over buffer diff --git a/tower-buffer/src/worker.rs b/tower-buffer/src/worker.rs index 1fff09b..52a4f36 100644 --- a/tower-buffer/src/worker.rs +++ b/tower-buffer/src/worker.rs @@ -1,6 +1,8 @@ -use error::{Closed, Error, ServiceError, SpawnError}; -use futures::{Async, Future, Poll, Stream}; -use message::Message; +use crate::{ + error::{Closed, Error, ServiceError, SpawnError}, + message::Message, +}; +use futures::{try_ready, Async, Future, Poll, Stream}; use std::sync::{Arc, Mutex}; use tokio_executor::TypedExecutor; use tokio_sync::mpsc; diff --git a/tower-buffer/tests/buffer.rs b/tower-buffer/tests/buffer.rs index 8ea019f..3f61b6e 100644 --- a/tower-buffer/tests/buffer.rs +++ b/tower-buffer/tests/buffer.rs @@ -1,18 +1,11 @@ -extern crate futures; -extern crate tokio_executor; -extern crate tower_buffer; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - use futures::prelude::*; +use std::{cell::RefCell, thread}; use tokio_executor::{SpawnError, TypedExecutor}; -use tower_buffer::*; -use tower_service::*; -use tower_test::mock; - -use std::cell::RefCell; -use std::thread; +use tower::{ + buffer::{error, Buffer}, + Service, +}; +use tower_test::{assert_request_eq, mock}; #[test] fn req_and_res() { diff --git a/tower-discover/Cargo.toml b/tower-discover/Cargo.toml index 26293ba..e9ba664 100644 --- a/tower-discover/Cargo.toml +++ b/tower-discover/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-discover" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-discover/src/error.rs b/tower-discover/src/error.rs index 03df6c1..cec3de4 100644 --- a/tower-discover/src/error.rs +++ b/tower-discover/src/error.rs @@ -1,5 +1,4 @@ -use std::error::Error; -use std::fmt; +use std::{error::Error, fmt}; #[derive(Debug)] pub enum Never {} diff --git a/tower-discover/src/lib.rs b/tower-discover/src/lib.rs index 423f283..2fe5c3e 100644 --- a/tower-discover/src/lib.rs +++ b/tower-discover/src/lib.rs @@ -1,3 +1,6 @@ +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] + //! # Tower service discovery //! //! Service discovery is the automatic detection of services available to the @@ -5,16 +8,11 @@ //! via the network; however, it is possible to discover services available in //! other processes or even in process. -#[macro_use] -extern crate futures; -extern crate tower_service; - mod error; mod list; mod stream; -pub use crate::list::ServiceList; -pub use crate::stream::ServiceStream; +pub use crate::{list::ServiceList, stream::ServiceStream}; use futures::Poll; use std::hash::Hash; diff --git a/tower-discover/src/list.rs b/tower-discover/src/list.rs index 4cde65d..125839a 100644 --- a/tower-discover/src/list.rs +++ b/tower-discover/src/list.rs @@ -1,5 +1,4 @@ -use crate::error::Never; -use crate::{Change, Discover}; +use crate::{error::Never, Change, Discover}; use futures::{Async, Poll}; use std::iter::{Enumerate, IntoIterator}; use tower_service::Service; diff --git a/tower-discover/src/stream.rs b/tower-discover/src/stream.rs index 302be86..fc65656 100644 --- a/tower-discover/src/stream.rs +++ b/tower-discover/src/stream.rs @@ -1,5 +1,5 @@ use crate::{Change, Discover}; -use futures::{Async, Poll, Stream}; +use futures::{try_ready, Async, Poll, Stream}; use std::hash::Hash; use tower_service::Service; diff --git a/tower-filter/Cargo.toml b/tower-filter/Cargo.toml index 7df0693..0e29561 100644 --- a/tower-filter/Cargo.toml +++ b/tower-filter/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-filter" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-filter/src/error.rs b/tower-filter/src/error.rs index 9b23605..f6e06bd 100644 --- a/tower-filter/src/error.rs +++ b/tower-filter/src/error.rs @@ -1,7 +1,6 @@ //! Error types -use std::error; -use std::fmt; +use std::{error, fmt}; /// Error produced by `Filter` #[derive(Debug)] diff --git a/tower-filter/src/future.rs b/tower-filter/src/future.rs index 6685d93..baa90ff 100644 --- a/tower-filter/src/future.rs +++ b/tower-filter/src/future.rs @@ -1,6 +1,6 @@ //! Future types -use error::{self, Error}; +use crate::error::{self, Error}; use futures::{Async, Future, Poll}; use tower_service::Service; diff --git a/tower-filter/src/layer.rs b/tower-filter/src/layer.rs index e55b970..e78c1a9 100644 --- a/tower-filter/src/layer.rs +++ b/tower-filter/src/layer.rs @@ -1,7 +1,9 @@ -use error::{self, Error}; +use crate::{ + error::{self, Error}, + Filter, Predicate, +}; use tower_layer::Layer; use tower_service::Service; -use {Filter, Predicate}; pub struct FilterLayer { predicate: U, diff --git a/tower-filter/src/lib.rs b/tower-filter/src/lib.rs index 5dbe866..9277643 100644 --- a/tower-filter/src/lib.rs +++ b/tower-filter/src/lib.rs @@ -1,20 +1,17 @@ +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] + //! Conditionally dispatch requests to the inner service based on the result of //! a predicate. -extern crate futures; -extern crate tower_layer; -extern crate tower_service; - pub mod error; pub mod future; mod layer; mod predicate; -pub use layer::FilterLayer; -pub use predicate::Predicate; +pub use crate::{layer::FilterLayer, predicate::Predicate}; -use error::Error; -use future::ResponseFuture; +use crate::{error::Error, future::ResponseFuture}; use futures::Poll; use tower_service::Service; diff --git a/tower-filter/src/predicate.rs b/tower-filter/src/predicate.rs index 32569c7..970bee5 100644 --- a/tower-filter/src/predicate.rs +++ b/tower-filter/src/predicate.rs @@ -1,4 +1,4 @@ -use error::Error; +use crate::error::Error; use futures::{Future, IntoFuture}; /// Checks a request diff --git a/tower-filter/tests/filter.rs b/tower-filter/tests/filter.rs index c7a84dd..5cc9569 100644 --- a/tower-filter/tests/filter.rs +++ b/tower-filter/tests/filter.rs @@ -1,16 +1,8 @@ -extern crate futures; -extern crate tower_filter; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - use futures::*; -use tower_filter::error::Error; -use tower_filter::Filter; -use tower_service::*; -use tower_test::mock; - use std::thread; +use tower_filter::{error::Error, Filter}; +use tower_service::Service; +use tower_test::{assert_request_eq, mock}; #[test] fn passthrough_sync() { diff --git a/tower-layer/Cargo.toml b/tower-layer/Cargo.toml index eaeba1c..ae98e11 100644 --- a/tower-layer/Cargo.toml +++ b/tower-layer/Cargo.toml @@ -15,6 +15,7 @@ description = """ Decorates a `Service` to allow easy composition between `Service`s. """ categories = ["asynchronous", "network-programming"] +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-layer/src/lib.rs b/tower-layer/src/lib.rs index e36d04e..56055b6 100644 --- a/tower-layer/src/lib.rs +++ b/tower-layer/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(missing_docs)] +#![deny(missing_docs, rust_2018_idioms)] #![doc(html_root_url = "https://docs.rs/tower-layer/0.1.0")] //! Layer traits and extensions. @@ -8,9 +8,6 @@ //! //! A middleware implements the [`Layer`] and [`Service`] trait. -extern crate futures; -extern crate tower_service; - use tower_service::Service; /// Decorates a `Service`, transforming either the request or the response. diff --git a/tower-limit/Cargo.toml b/tower-limit/Cargo.toml index 663b19c..9078169 100644 --- a/tower-limit/Cargo.toml +++ b/tower-limit/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-limit" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-limit/src/concurrency/layer.rs b/tower-limit/src/concurrency/layer.rs index 18e510c..30f7f22 100644 --- a/tower-limit/src/concurrency/layer.rs +++ b/tower-limit/src/concurrency/layer.rs @@ -1,5 +1,4 @@ -use super::never::Never; -use super::{ConcurrencyLimit, Error}; +use super::{never::Never, ConcurrencyLimit, Error}; use tower_layer::Layer; use tower_service::Service; diff --git a/tower-limit/src/concurrency/mod.rs b/tower-limit/src/concurrency/mod.rs index 9923b25..de9cf2a 100644 --- a/tower-limit/src/concurrency/mod.rs +++ b/tower-limit/src/concurrency/mod.rs @@ -5,7 +5,6 @@ mod layer; mod never; mod service; -pub use self::layer::ConcurrencyLimitLayer; -pub use self::service::ConcurrencyLimit; +pub use self::{layer::ConcurrencyLimitLayer, service::ConcurrencyLimit}; type Error = Box; diff --git a/tower-limit/src/concurrency/service.rs b/tower-limit/src/concurrency/service.rs index 799eb86..61e6494 100644 --- a/tower-limit/src/concurrency/service.rs +++ b/tower-limit/src/concurrency/service.rs @@ -1,9 +1,8 @@ -use super::future::ResponseFuture; -use super::Error; +use super::{future::ResponseFuture, Error}; use tower_service::Service; -use futures::Poll; +use futures::{try_ready, Poll}; use std::sync::Arc; use tokio_sync::semaphore::{self, Semaphore}; diff --git a/tower-limit/src/lib.rs b/tower-limit/src/lib.rs index 8f00746..814342b 100644 --- a/tower-limit/src/lib.rs +++ b/tower-limit/src/lib.rs @@ -1,14 +1,11 @@ +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] //! Limit inbound requests. -#[macro_use] -extern crate futures; -extern crate tokio_sync; -extern crate tokio_timer; -extern crate tower_layer; -extern crate tower_service; - pub mod concurrency; pub mod rate; -pub use crate::concurrency::{ConcurrencyLimit, ConcurrencyLimitLayer}; -pub use crate::rate::{RateLimit, RateLimitLayer}; +pub use crate::{ + concurrency::{ConcurrencyLimit, ConcurrencyLimitLayer}, + rate::{RateLimit, RateLimitLayer}, +}; diff --git a/tower-limit/src/rate/error.rs b/tower-limit/src/rate/error.rs index aa2eaa9..59b3a91 100644 --- a/tower-limit/src/rate/error.rs +++ b/tower-limit/src/rate/error.rs @@ -1,6 +1,6 @@ use std::error; -pub(crate) type Error = Box; +pub(crate) type Error = Box; pub(crate) mod never { use std::{error, fmt}; diff --git a/tower-limit/src/rate/layer.rs b/tower-limit/src/rate/layer.rs index 71cc2ff..2652839 100644 --- a/tower-limit/src/rate/layer.rs +++ b/tower-limit/src/rate/layer.rs @@ -1,5 +1,7 @@ -use super::error::{never::Never, Error}; -use super::{Rate, RateLimit}; +use super::{ + error::{never::Never, Error}, + Rate, RateLimit, +}; use std::time::Duration; use tower_layer::Layer; use tower_service::Service; diff --git a/tower-limit/src/rate/mod.rs b/tower-limit/src/rate/mod.rs index 36a007d..05d185e 100644 --- a/tower-limit/src/rate/mod.rs +++ b/tower-limit/src/rate/mod.rs @@ -6,6 +6,4 @@ mod layer; mod rate; mod service; -pub use self::layer::RateLimitLayer; -pub use self::rate::Rate; -pub use self::service::RateLimit; +pub use self::{layer::RateLimitLayer, rate::Rate, service::RateLimit}; diff --git a/tower-limit/src/rate/service.rs b/tower-limit/src/rate/service.rs index 712aa3e..10cb99f 100644 --- a/tower-limit/src/rate/service.rs +++ b/tower-limit/src/rate/service.rs @@ -1,7 +1,5 @@ -use super::error::Error; -use super::future::ResponseFuture; -use super::Rate; -use futures::{Future, Poll}; +use super::{error::Error, future::ResponseFuture, Rate}; +use futures::{try_ready, Future, Poll}; use tokio_timer::{clock, Delay}; use tower_service::Service; diff --git a/tower-limit/tests/concurrency.rs b/tower-limit/tests/concurrency.rs index 404dd4e..3d0f0d1 100644 --- a/tower-limit/tests/concurrency.rs +++ b/tower-limit/tests/concurrency.rs @@ -1,16 +1,11 @@ -extern crate futures; -extern crate tokio_mock_task; -extern crate tower_limit; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - +use futures::{ + self, + future::{poll_fn, Future}, +}; +use tokio_mock_task::MockTask; use tower_limit::concurrency::ConcurrencyLimit; use tower_service::Service; -use tower_test::mock; - -use futures::future::{poll_fn, Future}; -use tokio_mock_task::MockTask; +use tower_test::{assert_request_eq, mock}; macro_rules! assert_ready { ($e:expr) => {{ diff --git a/tower-limit/tests/rate.rs b/tower-limit/tests/rate.rs index 1d05606..fbc56fe 100644 --- a/tower-limit/tests/rate.rs +++ b/tower-limit/tests/rate.rs @@ -1,15 +1,9 @@ -extern crate futures; -extern crate tokio; -extern crate tokio_timer; -extern crate tower_limit; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - use futures::future; +use tokio::runtime::current_thread::Runtime; +use tokio_timer::Delay; use tower_limit::rate::*; use tower_service::*; -use tower_test::mock; +use tower_test::{assert_request_eq, mock}; use std::time::{Duration, Instant}; @@ -36,7 +30,7 @@ macro_rules! assert_not_ready { #[test] fn reaching_capacity() { - let mut rt = tokio::runtime::current_thread::Runtime::new().unwrap(); + let mut rt = Runtime::new().unwrap(); let (mut service, mut handle) = new_service(Rate::new(1, from_millis(100))); assert_ready!(service.poll_ready()); @@ -57,10 +51,8 @@ fn reaching_capacity() { assert!(poll_request.unwrap().is_not_ready()); // Unlike `thread::sleep`, this advances the timer. - rt.block_on(tokio_timer::Delay::new( - Instant::now() + Duration::from_millis(100), - )) - .unwrap(); + rt.block_on(Delay::new(Instant::now() + Duration::from_millis(100))) + .unwrap(); let poll_ready = rt.block_on(future::lazy(|| service.poll_ready())); assert_ready!(poll_ready); diff --git a/tower-load-shed/Cargo.toml b/tower-load-shed/Cargo.toml index fb10c97..784d927 100644 --- a/tower-load-shed/Cargo.toml +++ b/tower-load-shed/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-load-shed" version = "0.1.0" authors = ["Sean McArthur "] publish = false +edition = "2018" [dependencies] futures = "0.1.25" diff --git a/tower-load-shed/src/future.rs b/tower-load-shed/src/future.rs index d25ff75..5c6922c 100644 --- a/tower-load-shed/src/future.rs +++ b/tower-load-shed/src/future.rs @@ -2,7 +2,7 @@ use std::fmt; use futures::{Future, Poll}; -use error::{Error, Overloaded}; +use crate::error::{Error, Overloaded}; /// Future for the `LoadShed` service. pub struct ResponseFuture { diff --git a/tower-load-shed/src/layer.rs b/tower-load-shed/src/layer.rs index bfa9c66..83f9468 100644 --- a/tower-load-shed/src/layer.rs +++ b/tower-load-shed/src/layer.rs @@ -1,8 +1,10 @@ use tower_layer::Layer; use tower_service::Service; -use error::{Error, Never}; -use LoadShed; +use crate::{ + error::{Error, Never}, + LoadShed, +}; /// A `tower-layer` to wrap services in `LoadShed` middleware. #[derive(Debug)] diff --git a/tower-load-shed/src/lib.rs b/tower-load-shed/src/lib.rs index 700db43..ef7a987 100644 --- a/tower-load-shed/src/lib.rs +++ b/tower-load-shed/src/lib.rs @@ -1,13 +1,11 @@ #![cfg_attr(test, deny(warnings))] #![deny(missing_debug_implementations)] #![deny(missing_docs)] +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] //! tower-load-shed -extern crate futures; -extern crate tower_layer; -extern crate tower_service; - use futures::Poll; use tower_service::Service; @@ -16,8 +14,7 @@ mod future; mod layer; use self::error::Error; -pub use self::future::ResponseFuture; -pub use self::layer::LoadShedLayer; +pub use self::{future::ResponseFuture, layer::LoadShedLayer}; /// A `Service` that sheds load when the inner service isn't ready. #[derive(Debug)] diff --git a/tower-load-shed/tests/load-shed.rs b/tower-load-shed/tests/load-shed.rs index 31113d6..9c7970e 100644 --- a/tower-load-shed/tests/load-shed.rs +++ b/tower-load-shed/tests/load-shed.rs @@ -1,13 +1,7 @@ -extern crate futures; -extern crate tower_load_shed; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - use futures::Future; -use tower_load_shed::LoadShed; +use tower_load_shed::{self, LoadShed}; use tower_service::Service; -use tower_test::mock; +use tower_test::{assert_request_eq, mock}; #[test] fn when_ready() { diff --git a/tower-reconnect/Cargo.toml b/tower-reconnect/Cargo.toml index 000a049..154f3ef 100644 --- a/tower-reconnect/Cargo.toml +++ b/tower-reconnect/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-reconnect" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] log = "0.4.1" diff --git a/tower-reconnect/src/future.rs b/tower-reconnect/src/future.rs index 1d97b49..fffeb8f 100644 --- a/tower-reconnect/src/future.rs +++ b/tower-reconnect/src/future.rs @@ -1,5 +1,5 @@ +use crate::Error; use futures::{Future, Poll}; -use Error; pub struct ResponseFuture { inner: F, diff --git a/tower-reconnect/src/lib.rs b/tower-reconnect/src/lib.rs index 47ef82f..8573f6c 100644 --- a/tower-reconnect/src/lib.rs +++ b/tower-reconnect/src/lib.rs @@ -1,19 +1,15 @@ -extern crate futures; -#[macro_use] -extern crate log; -extern crate tower_service; -extern crate tower_util; +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] pub mod future; use crate::future::ResponseFuture; - use futures::{Async, Future, Poll}; +use log::trace; +use std::fmt; use tower_service::Service; use tower_util::MakeService; -use std::fmt; - pub struct Reconnect where M: Service, @@ -23,7 +19,7 @@ where target: Target, } -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; #[derive(Debug)] enum State { diff --git a/tower-retry/Cargo.toml b/tower-retry/Cargo.toml index fc418d9..13cb3b7 100644 --- a/tower-retry/Cargo.toml +++ b/tower-retry/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-retry" version = "0.1.0" authors = ["Sean McArthur "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-retry/src/budget.rs b/tower-retry/src/budget.rs index 134081e..c1497aa 100644 --- a/tower-retry/src/budget.rs +++ b/tower-retry/src/budget.rs @@ -1,12 +1,13 @@ //! A retry "budget" for allowing only a certain amount of retries over time. -use std::fmt; -use std::sync::{ - atomic::{AtomicIsize, Ordering}, - Mutex, +use std::{ + fmt, + sync::{ + atomic::{AtomicIsize, Ordering}, + Mutex, + }, + time::{Duration, Instant}, }; -use std::time::{Duration, Instant}; - use tokio_timer::clock; /// Represents a "budget" for retrying requests. @@ -212,12 +213,13 @@ impl Bucket { #[cfg(test)] mod tests { - extern crate tokio_executor; - use self::tokio_executor::enter; use super::*; - use std::sync::{Arc, Mutex, MutexGuard}; - use std::time::Instant; + use std::{ + sync::{Arc, Mutex, MutexGuard}, + time::Instant, + }; + use tokio_executor; #[test] fn empty() { diff --git a/tower-retry/src/lib.rs b/tower-retry/src/lib.rs index 1e5b3a6..fc91142 100644 --- a/tower-retry/src/lib.rs +++ b/tower-retry/src/lib.rs @@ -1,23 +1,19 @@ #![deny(missing_debug_implementations)] #![deny(missing_docs)] #![deny(warnings)] +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] //! Tower middleware for retrying "failed" requests. -#[macro_use] -extern crate futures; -extern crate tokio_timer; -extern crate tower_layer; -extern crate tower_service; - -use futures::{Async, Future, Poll}; +use futures::{try_ready, Async, Future, Poll}; use tower_layer::Layer; use tower_service::Service; pub mod budget; mod never; -use never::Never; +use crate::never::Never; /// A "retry policy" to classify if a request should be retried. /// diff --git a/tower-retry/tests/retry.rs b/tower-retry/tests/retry.rs index 3f334c8..821e6c8 100644 --- a/tower-retry/tests/retry.rs +++ b/tower-retry/tests/retry.rs @@ -1,13 +1,7 @@ -extern crate futures; -extern crate tower_retry; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - use futures::{future, Future}; use tower_retry::Policy; use tower_service::Service; -use tower_test::mock; +use tower_test::{assert_request_eq, mock}; #[test] fn retry_errors() { @@ -83,7 +77,7 @@ fn success_with_cannot_clone() { type Req = &'static str; type Res = &'static str; type InnerError = &'static str; -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; type Mock = mock::Mock; type Handle = mock::Handle; diff --git a/tower-test/Cargo.toml b/tower-test/Cargo.toml index 30b0f39..d66714a 100644 --- a/tower-test/Cargo.toml +++ b/tower-test/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-test" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-test/src/lib.rs b/tower-test/src/lib.rs index f94244f..0a7f41c 100644 --- a/tower-test/src/lib.rs +++ b/tower-test/src/lib.rs @@ -1,8 +1,7 @@ -//! Mock `Service` that can be used in tests. +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] -extern crate futures; -extern crate tokio_sync; -extern crate tower_service; +//! Mock `Service` that can be used in tests. mod macros; pub mod mock; diff --git a/tower-test/src/mock/error.rs b/tower-test/src/mock/error.rs index 1fb3064..7005f9d 100644 --- a/tower-test/src/mock/error.rs +++ b/tower-test/src/mock/error.rs @@ -1,9 +1,8 @@ //! Error types -use std::error; -use std::fmt; +use std::{error, fmt}; -pub(crate) type Error = Box; +pub(crate) type Error = Box; #[derive(Debug)] pub struct Closed(()); diff --git a/tower-test/src/mock/future.rs b/tower-test/src/mock/future.rs index 58ff18f..81990aa 100644 --- a/tower-test/src/mock/future.rs +++ b/tower-test/src/mock/future.rs @@ -1,6 +1,6 @@ //! Future types -use super::error::{self, Error}; +use crate::mock::error::{self, Error}; use futures::{Async, Future, Poll}; use tokio_sync::oneshot; diff --git a/tower-test/src/mock/mod.rs b/tower-test/src/mock/mod.rs index 1a7c39b..e3e3988 100644 --- a/tower-test/src/mock/mod.rs +++ b/tower-test/src/mock/mod.rs @@ -3,16 +3,19 @@ pub mod error; pub mod future; -use self::error::Error; -use self::future::ResponseFuture; -use futures::task::{self, Task}; -use futures::{Async, Future, Poll, Stream}; +use crate::mock::{error::Error, future::ResponseFuture}; +use futures::{ + task::{self, Task}, + Async, Future, Poll, Stream, +}; use tokio_sync::{mpsc, oneshot}; use tower_service::Service; -use std::collections::HashMap; -use std::sync::{Arc, Mutex}; -use std::u64; +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, + u64, +}; /// A mock service #[derive(Debug)] diff --git a/tower-test/tests/mock.rs b/tower-test/tests/mock.rs index fc98355..a58a427 100644 --- a/tower-test/tests/mock.rs +++ b/tower-test/tests/mock.rs @@ -1,12 +1,6 @@ -extern crate futures; -extern crate tower_service; -#[macro_use] -extern crate tower_test; - -use tower_service::Service; -use tower_test::mock; - use futures::Future; +use tower_service::Service; +use tower_test::{assert_request_eq, mock}; #[test] fn single_request_ready() { diff --git a/tower-timeout/Cargo.toml b/tower-timeout/Cargo.toml index 8708c7c..5635876 100644 --- a/tower-timeout/Cargo.toml +++ b/tower-timeout/Cargo.toml @@ -3,6 +3,7 @@ name = "tower-timeout" version = "0.1.0" authors = ["Carl Lerche "] publish = false +edition = "2018" [dependencies] futures = "0.1" diff --git a/tower-timeout/src/error.rs b/tower-timeout/src/error.rs index 6853297..21123c7 100644 --- a/tower-timeout/src/error.rs +++ b/tower-timeout/src/error.rs @@ -2,7 +2,7 @@ use std::{error, fmt}; -pub(crate) type Error = Box; +pub(crate) type Error = Box; /// The timeout elapsed. #[derive(Debug)] diff --git a/tower-timeout/src/layer.rs b/tower-timeout/src/layer.rs index 66b796f..fbf3680 100644 --- a/tower-timeout/src/layer.rs +++ b/tower-timeout/src/layer.rs @@ -1,5 +1,4 @@ -use crate::{Error, Timeout}; -use never::Never; +use crate::{never::Never, Error, Timeout}; use std::time::Duration; use tower_layer::Layer; use tower_service::Service; diff --git a/tower-timeout/src/lib.rs b/tower-timeout/src/lib.rs index 1c4399c..d58d7c4 100644 --- a/tower-timeout/src/lib.rs +++ b/tower-timeout/src/lib.rs @@ -4,14 +4,10 @@ //! will be aborted. #![doc(html_root_url = "https://docs.rs/tower-timeout/0.1.0")] -#![deny(missing_debug_implementations, missing_docs)] +#![deny(missing_debug_implementations, missing_docs, rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] #![cfg_attr(test, deny(warnings))] -extern crate futures; -extern crate tokio_timer; -extern crate tower_layer; -extern crate tower_service; - pub mod error; pub mod future; mod layer; @@ -19,8 +15,7 @@ mod never; pub use crate::layer::TimeoutLayer; -use crate::error::Error; -use crate::future::ResponseFuture; +use crate::{error::Error, future::ResponseFuture}; use futures::Poll; use tokio_timer::{clock, Delay}; diff --git a/tower-util/Cargo.toml b/tower-util/Cargo.toml index 7311234..1327543 100644 --- a/tower-util/Cargo.toml +++ b/tower-util/Cargo.toml @@ -17,6 +17,7 @@ description = """ Utilities for working with tower-service. """ categories = ["asynchronous", "network-programming"] +edition = "2018" [features] io = ["tokio-io"] diff --git a/tower-util/src/boxed/mod.rs b/tower-util/src/boxed/mod.rs index a61f4ad..f56833f 100644 --- a/tower-util/src/boxed/mod.rs +++ b/tower-util/src/boxed/mod.rs @@ -58,5 +58,4 @@ mod sync; mod unsync; -pub use self::sync::BoxService; -pub use self::unsync::UnsyncBoxService; +pub use self::{sync::BoxService, unsync::UnsyncBoxService}; diff --git a/tower-util/src/boxed/sync.rs b/tower-util/src/boxed/sync.rs index ae19182..f5d38db 100644 --- a/tower-util/src/boxed/sync.rs +++ b/tower-util/src/boxed/sync.rs @@ -11,14 +11,14 @@ use std::fmt; /// /// See module level documentation for more details. pub struct BoxService { - inner: Box> + Send>, + inner: Box> + Send>, } /// A boxed `Future + Send` trait object. /// /// This type alias represents a boxed future that is `Send` and can be moved /// across threads. -type BoxFuture = Box + Send>; +type BoxFuture = Box + Send>; #[derive(Debug)] struct Boxed { @@ -68,7 +68,7 @@ where { type Response = S::Response; type Error = S::Error; - type Future = Box + Send>; + type Future = Box + Send>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { self.inner.poll_ready() diff --git a/tower-util/src/boxed/unsync.rs b/tower-util/src/boxed/unsync.rs index f1151d3..c82990a 100644 --- a/tower-util/src/boxed/unsync.rs +++ b/tower-util/src/boxed/unsync.rs @@ -5,14 +5,14 @@ use std::fmt; /// A boxed `Service` trait object. pub struct UnsyncBoxService { - inner: Box>>, + inner: Box>>, } /// A boxed `Future` trait object. /// /// This type alias represents a boxed future that is *not* `Send` and must /// remain on the current thread. -type UnsyncBoxFuture = Box>; +type UnsyncBoxFuture = Box>; #[derive(Debug)] struct UnsyncBoxed { @@ -62,7 +62,7 @@ where { type Response = S::Response; type Error = S::Error; - type Future = Box>; + type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { self.inner.poll_ready() diff --git a/tower-util/src/call_all/mod.rs b/tower-util/src/call_all/mod.rs index 9cc8cd1..9921ffe 100644 --- a/tower-util/src/call_all/mod.rs +++ b/tower-util/src/call_all/mod.rs @@ -4,7 +4,6 @@ mod common; mod ordered; mod unordered; -pub use self::ordered::CallAll; -pub use self::unordered::CallAllUnordered; +pub use self::{ordered::CallAll, unordered::CallAllUnordered}; -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; diff --git a/tower-util/src/call_all/ordered.rs b/tower-util/src/call_all/ordered.rs index 497f797..a6f69c9 100644 --- a/tower-util/src/call_all/ordered.rs +++ b/tower-util/src/call_all/ordered.rs @@ -1,8 +1,7 @@ //! `Stream` + `Service` => `Stream`. use super::{common, Error}; -use futures::stream::FuturesOrdered; -use futures::{Future, Poll, Stream}; +use futures::{stream::FuturesOrdered, Future, Poll, Stream}; use tower_service::Service; /// This is a `futures::Stream` of responses resulting from calling the wrapped `tower::Service` diff --git a/tower-util/src/call_all/unordered.rs b/tower-util/src/call_all/unordered.rs index 99f5910..9469dba 100644 --- a/tower-util/src/call_all/unordered.rs +++ b/tower-util/src/call_all/unordered.rs @@ -1,8 +1,7 @@ //! `Stream` + `Service` => `Stream`. use super::{common, Error}; -use futures::stream::FuturesUnordered; -use futures::{Future, Poll, Stream}; +use futures::{stream::FuturesUnordered, Future, Poll, Stream}; use tower_service::Service; /// A stream of responses received from the inner service in received order. diff --git a/tower-util/src/either.rs b/tower-util/src/either.rs index 0a035fa..c832390 100644 --- a/tower-util/src/either.rs +++ b/tower-util/src/either.rs @@ -15,7 +15,7 @@ pub enum Either { B(B), } -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; impl Service for Either where diff --git a/tower-util/src/layer/mod.rs b/tower-util/src/layer/mod.rs index f1f6c5c..168176d 100644 --- a/tower-util/src/layer/mod.rs +++ b/tower-util/src/layer/mod.rs @@ -1,5 +1,4 @@ mod chain; mod identity; -pub use self::chain::Chain; -pub use self::identity::Identity; +pub use self::{chain::Chain, identity::Identity}; diff --git a/tower-util/src/lib.rs b/tower-util/src/lib.rs index d1a2e15..14207f4 100644 --- a/tower-util/src/lib.rs +++ b/tower-util/src/lib.rs @@ -1,11 +1,6 @@ //! Various utility types and functions that are generally with Tower. - -#[macro_use] -extern crate futures; -#[cfg(feature = "io")] -extern crate tokio_io; -extern crate tower_layer; -extern crate tower_service; +#![deny(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] mod boxed; mod call_all; @@ -20,16 +15,18 @@ mod ready; mod sealed; mod service_fn; -pub use crate::boxed::{BoxService, UnsyncBoxService}; -pub use crate::call_all::{CallAll, CallAllUnordered}; -pub use crate::either::Either; #[cfg(feature = "io")] pub use crate::make_connection::MakeConnection; -pub use crate::make_service::MakeService; -pub use crate::oneshot::Oneshot; -pub use crate::optional::Optional; -pub use crate::ready::Ready; -pub use crate::service_fn::ServiceFn; +pub use crate::{ + boxed::{BoxService, UnsyncBoxService}, + call_all::{CallAll, CallAllUnordered}, + either::Either, + make_service::MakeService, + oneshot::Oneshot, + optional::Optional, + ready::Ready, + service_fn::ServiceFn, +}; pub mod error { //! Error types diff --git a/tower-util/src/optional/error.rs b/tower-util/src/optional/error.rs index c90d015..3ed2e00 100644 --- a/tower-util/src/optional/error.rs +++ b/tower-util/src/optional/error.rs @@ -1,10 +1,9 @@ -use std::error; -use std::fmt; +use std::{error, fmt}; #[derive(Debug)] pub struct None(()); -pub(crate) type Error = Box; +pub(crate) type Error = Box; impl None { pub(crate) fn new() -> None { diff --git a/tower-util/src/optional/mod.rs b/tower-util/src/optional/mod.rs index c048be1..90c29bd 100644 --- a/tower-util/src/optional/mod.rs +++ b/tower-util/src/optional/mod.rs @@ -6,8 +6,7 @@ pub mod error; pub mod future; -use self::error::Error; -use self::future::ResponseFuture; +use self::{error::Error, future::ResponseFuture}; use futures::Poll; use tower_service::Service; diff --git a/tower-util/src/ready.rs b/tower-util/src/ready.rs index 9287f9e..4d1d03d 100644 --- a/tower-util/src/ready.rs +++ b/tower-util/src/ready.rs @@ -1,7 +1,6 @@ -use std::fmt; -use std::marker::PhantomData; +use std::{fmt, marker::PhantomData}; -use futures::{Future, Poll}; +use futures::{try_ready, Future, Poll}; use tower_service::Service; /// Future yielding a `Service` once the service is ready to process a request diff --git a/tower-util/tests/call_all.rs b/tower-util/tests/call_all.rs index f8c3d6d..f53e004 100644 --- a/tower-util/tests/call_all.rs +++ b/tower-util/tests/call_all.rs @@ -1,21 +1,14 @@ -extern crate futures; -extern crate tokio_mock_task; -extern crate tower; -extern crate tower_service; -#[macro_use] -extern crate tower_test; -extern crate tower_util; - -use futures::future::{ok, FutureResult}; -use futures::stream; -use futures::{Async, Poll, Stream}; -use std::cell::Cell; -use std::rc::Rc; +use futures::{ + self, + future::{ok, FutureResult}, + stream, Async, Poll, Stream, +}; +use std::{cell::Cell, rc::Rc}; use tower::ServiceExt; use tower_service::*; -use tower_test::mock; +use tower_test::{assert_request_eq, mock}; -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; #[derive(Debug, Eq, PartialEq)] struct Srv { diff --git a/tower/Cargo.toml b/tower/Cargo.toml index 84a094d..5d74883 100644 --- a/tower/Cargo.toml +++ b/tower/Cargo.toml @@ -12,6 +12,7 @@ clients and servers. """ categories = ["asynchronous", "network-programming"] keywords = ["io", "async", "non-blocking", "futures", "service"] +edition = "2018" [features] default = ["full"] diff --git a/tower/examples/channel_service.rs b/tower/examples/channel_service.rs index b8cc154..61f7fb1 100644 --- a/tower/examples/channel_service.rs +++ b/tower/examples/channel_service.rs @@ -9,28 +9,18 @@ #![deny(warnings)] -extern crate futures; -extern crate futures_cpupool; -extern crate tokio_timer; -extern crate tower; -extern crate tower_service; - -#[macro_use] -extern crate log; - -extern crate env_logger; - -use tower::{MakeService, ServiceExt}; -use tower_service::Service; - -use futures::future::{Executor, FutureResult}; -use futures::sync::{mpsc, oneshot}; -use futures::{Async, Future, IntoFuture, Poll, Stream}; +use env_logger; +use futures::{ + future::{Executor, FutureResult}, + sync::{mpsc, oneshot}, + Async, Future, IntoFuture, Poll, Stream, +}; use futures_cpupool::CpuPool; +use log::info; use tokio_timer::Timer; +use tower::{MakeService, Service, ServiceExt}; -use std::io; -use std::time::Duration; +use std::{io, time::Duration}; /// Service that dispatches requests to a side task using a channel. #[derive(Debug)] diff --git a/tower/examples/client.rs b/tower/examples/client.rs index 3861cd1..08f0434 100644 --- a/tower/examples/client.rs +++ b/tower/examples/client.rs @@ -1,29 +1,15 @@ -extern crate futures; -extern crate hyper; -extern crate tower; -extern crate tower_buffer; -extern crate tower_hyper; -extern crate tower_limit; -extern crate tower_reconnect; -extern crate tower_retry; -extern crate tower_service; - use futures::Future; -use hyper::client::connect::Destination; -use hyper::client::HttpConnector; -use hyper::{Request, Response, Uri}; +use hyper::{ + client::{connect::Destination, HttpConnector}, + Request, Response, Uri, +}; use std::time::Duration; -use tower::builder::ServiceBuilder; -use tower::ServiceExt; -use tower_buffer::BufferLayer; -use tower_hyper::client::{Builder, Connect}; -use tower_hyper::retry::{Body, RetryPolicy}; -use tower_hyper::util::Connector; -use tower_limit::concurrency::ConcurrencyLimitLayer; -use tower_limit::rate::RateLimitLayer; -use tower_reconnect::Reconnect; -use tower_retry::RetryLayer; -use tower_service::Service; +use tower::{builder::ServiceBuilder, reconnect::Reconnect, Service, ServiceExt}; +use tower_hyper::{ + client::{Builder, Connect}, + retry::{Body, RetryPolicy}, + util::Connector, +}; fn main() { let fut = futures::lazy(|| { @@ -49,11 +35,11 @@ fn request() -> impl Future, Error = ()> { // - meet `RetryLayer`'s requirement that our service implement `Service + Clone` // - ..and to provide cheap clones on the service. let maker = ServiceBuilder::new() - .layer(BufferLayer::new(5)) - .layer(RateLimitLayer::new(5, Duration::from_secs(1))) - .layer(ConcurrencyLimitLayer::new(5)) - .layer(RetryLayer::new(policy)) - .layer(BufferLayer::new(5)) + .buffer(5) + .rate_limit(5, Duration::from_secs(1)) + .concurrency_limit(5) + .retry(policy) + .buffer(5) .make_service(hyper); // `Reconnect` accepts a destination and a MakeService, creating a new service diff --git a/tower/examples/server.rs b/tower/examples/server.rs index 965bcfb..ab272b4 100644 --- a/tower/examples/server.rs +++ b/tower/examples/server.rs @@ -1,19 +1,8 @@ -extern crate futures; -extern crate hyper; -extern crate tokio_tcp; -extern crate tower; -extern crate tower_hyper; -extern crate tower_limit; -extern crate tower_service; - use futures::{future, Future, Poll, Stream}; -use hyper::{Body, Request, Response}; +use hyper::{self, Body, Request, Response}; use tokio_tcp::TcpListener; -use tower::builder::ServiceBuilder; -use tower_hyper::body::LiftBody; -use tower_hyper::server::Server; -use tower_limit::concurrency::ConcurrencyLimitLayer; -use tower_service::Service; +use tower::{builder::ServiceBuilder, Service}; +use tower_hyper::{body::LiftBody, server::Server}; fn main() { hyper::rt::run(future::lazy(|| { @@ -23,7 +12,7 @@ fn main() { println!("Listening on http://{}", addr); let maker = ServiceBuilder::new() - .layer(ConcurrencyLimitLayer::new(5)) + .concurrency_limit(5) .make_service(MakeSvc); let server = Server::new(maker); @@ -67,7 +56,7 @@ struct MakeSvc; impl Service<()> for MakeSvc { type Response = Svc; type Error = hyper::Error; - type Future = Box + Send + 'static>; + type Future = Box + Send + 'static>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(().into()) diff --git a/tower/src/builder/mod.rs b/tower/src/builder/mod.rs index 38e985a..cb1e1ad 100644 --- a/tower/src/builder/mod.rs +++ b/tower/src/builder/mod.rs @@ -4,21 +4,24 @@ mod service; pub use self::service::{LayeredMakeService, ServiceFuture}; -use buffer::BufferLayer; -use limit::concurrency::ConcurrencyLimitLayer; -use limit::rate::RateLimitLayer; -use load_shed::LoadShedLayer; -use retry::RetryLayer; -use timeout::TimeoutLayer; +use crate::{ + buffer::BufferLayer, + limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer}, + load_shed::LoadShedLayer, + retry::RetryLayer, + timeout::TimeoutLayer, +}; use tower_layer::Layer; use tower_service::Service; -use tower_util::layer::{Chain, Identity}; -use tower_util::MakeService; +use tower_util::{ + layer::{Chain, Identity}, + MakeService, +}; use std::time::Duration; -pub(super) type Error = Box<::std::error::Error + Send + Sync>; +pub(super) type Error = Box; /// Declaratively construct Service values. /// diff --git a/tower/src/builder/service.rs b/tower/src/builder/service.rs index 2d74eb9..846381f 100644 --- a/tower/src/builder/service.rs +++ b/tower/src/builder/service.rs @@ -1,10 +1,9 @@ use super::Error; -use futures::{Async, Future, Poll}; -use std::marker::PhantomData; -use std::sync::Arc; +use crate::Service; +use futures::{try_ready, Async, Future, Poll}; +use std::{marker::PhantomData, sync::Arc}; use tower_layer::Layer; use tower_util::MakeService; -use Service; /// Composed `MakeService` produced from `ServiceBuilder` #[derive(Debug)] diff --git a/tower/src/layer.rs b/tower/src/layer.rs index e6c442a..63d0a8f 100644 --- a/tower/src/layer.rs +++ b/tower/src/layer.rs @@ -2,9 +2,9 @@ pub use tower_layer::Layer; +/// `util` exports an Identity Layer and Chain, a mechanism for chaining them. pub mod util { - pub use tower_util::layer::Chain; - pub use tower_util::layer::Identity; + pub use tower_util::layer::{Chain, Identity}; } /// An extension trait for `Layer`'s that provides a variety of convenient diff --git a/tower/src/lib.rs b/tower/src/lib.rs index 7e662e8..65a2bc3 100644 --- a/tower/src/lib.rs +++ b/tower/src/lib.rs @@ -1,30 +1,22 @@ // Allows refining features in the future without breaking backwards // compatibility #![cfg(feature = "full")] +#![deny(missing_docs, rust_2018_idioms)] //! Various utility types and functions that are generally with Tower. -#[macro_use] -extern crate futures; - -extern crate tower_layer; -extern crate tower_service; -extern crate tower_util; - -pub extern crate tower_buffer as buffer; -pub extern crate tower_discover as discover; -pub extern crate tower_limit as limit; -pub extern crate tower_load_shed as load_shed; -pub extern crate tower_reconnect as reconnect; -pub extern crate tower_retry as retry; -pub extern crate tower_timeout as timeout; +pub use tower_buffer as buffer; +pub use tower_discover as discover; +pub use tower_limit as limit; +pub use tower_load_shed as load_shed; +pub use tower_reconnect as reconnect; +pub use tower_retry as retry; +pub use tower_timeout as timeout; pub mod builder; pub mod layer; pub mod util; -pub use builder::ServiceBuilder; +pub use crate::{builder::ServiceBuilder, util::ServiceExt}; pub use tower_service::Service; -pub use tower_util::MakeConnection; -pub use tower_util::MakeService; -pub use util::ServiceExt; +pub use tower_util::{MakeConnection, MakeService}; diff --git a/tower/src/util.rs b/tower/src/util.rs index 212887f..720c719 100644 --- a/tower/src/util.rs +++ b/tower/src/util.rs @@ -1,21 +1,15 @@ //! Combinators for working with `Service`s -pub use tower_util::BoxService; -pub use tower_util::CallAll; -pub use tower_util::CallAllUnordered; -pub use tower_util::Either; -pub use tower_util::Oneshot; -pub use tower_util::Optional; -pub use tower_util::Ready; -pub use tower_util::ServiceFn; -pub use tower_util::UnsyncBoxService; - use futures::Stream; use tower_service::Service; +pub use tower_util::{ + BoxService, CallAll, CallAllUnordered, Either, Oneshot, Optional, Ready, ServiceFn, + UnsyncBoxService, +}; impl ServiceExt for T where T: Service {} -type Error = Box<::std::error::Error + Send + Sync>; +type Error = Box; /// An extension trait for `Service`s that provides a variety of convenient /// adapters diff --git a/tower/tests/builder.rs b/tower/tests/builder.rs index af83e83..9efaabd 100644 --- a/tower/tests/builder.rs +++ b/tower/tests/builder.rs @@ -1,20 +1,11 @@ -extern crate futures; -extern crate tokio; -extern crate tower; -extern crate tower_buffer; -extern crate tower_limit; -extern crate tower_reconnect; -extern crate tower_retry; -extern crate tower_service; -extern crate void; - -use futures::future::{self, FutureResult}; -use futures::prelude::*; +use futures::{ + future::{self, FutureResult}, + prelude::*, +}; use std::time::Duration; use tower::builder::ServiceBuilder; use tower_buffer::BufferLayer; -use tower_limit::concurrency::ConcurrencyLimitLayer; -use tower_limit::rate::RateLimitLayer; +use tower_limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer}; use tower_reconnect::Reconnect; use tower_retry::{Policy, RetryLayer}; use tower_service::*; @@ -121,7 +112,7 @@ struct MockPolicy; impl Policy for MockPolicy where - E: Into>, + E: Into>, { type Future = FutureResult;