Move Tower to 2018 Edition (#238)

This commit is contained in:
David Barsky 2019-04-08 23:11:09 -04:00 committed by Carl Lerche
parent 7769590f46
commit 17860191d7
91 changed files with 311 additions and 466 deletions

View File

@ -3,6 +3,7 @@ name = "tower-balance"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -1,30 +1,15 @@
//! Exercises load balancers with mocked services. //! Exercises load balancers with mocked services.
extern crate env_logger; use 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 futures::{future, stream, Future, Stream}; use futures::{future, stream, Future, Stream};
use hdrsample::Histogram; use hdrsample::Histogram;
use rand::Rng; use rand::{self, Rng};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use tokio::{runtime, timer}; 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_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 REQUESTS: usize = 50_000;
const CONCURRENCY: usize = 500; const CONCURRENCY: usize = 500;
@ -125,7 +110,7 @@ fn main() {
rt.shutdown_on_idle().wait().unwrap(); rt.shutdown_on_idle().wait().unwrap();
} }
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
fn gen_disco() -> impl Discover< fn gen_disco() -> impl Discover<
Key = usize, Key = usize,

View File

@ -3,8 +3,7 @@ use indexmap::IndexMap;
mod p2c; mod p2c;
mod round_robin; mod round_robin;
pub use self::p2c::PowerOfTwoChoices; pub use self::{p2c::PowerOfTwoChoices, round_robin::RoundRobin};
pub use self::round_robin::RoundRobin;
/// A strategy for choosing nodes. /// A strategy for choosing nodes.
// TODO hide `K` // TODO hide `K`
@ -32,15 +31,15 @@ pub struct TooFew;
/// Holds two or more services. /// Holds two or more services.
// TODO hide `K` // TODO hide `K`
pub struct Replicas<'a, K: 'a, S: 'a>(&'a IndexMap<K, S>); pub struct Replicas<'a, K, S>(&'a IndexMap<K, S>);
impl<'a, K: 'a, S: 'a> Replicas<'a, K, S> { impl<K, S> Replicas<'_, K, S> {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.len() self.0.len()
} }
} }
impl<'a, K: 'a, S: 'a> ::std::ops::Index<usize> for Replicas<'a, K, S> { impl<K, S> ::std::ops::Index<usize> for Replicas<'_, K, S> {
type Output = S; type Output = S;
fn index(&self, idx: usize) -> &Self::Output { fn index(&self, idx: usize) -> &Self::Output {

View File

@ -1,7 +1,10 @@
use log::trace;
use rand::{rngs::SmallRng, FromEntropy, Rng}; use rand::{rngs::SmallRng, FromEntropy, Rng};
use choose::{Choose, Replicas}; use crate::{
use Load; choose::{Choose, Replicas},
Load,
};
/// Chooses nodes using the [Power of Two Choices][p2c]. /// Chooses nodes using the [Power of Two Choices][p2c].
/// ///

View File

@ -1,4 +1,4 @@
use choose::{Choose, Replicas}; use crate::choose::{Choose, Replicas};
/// Chooses nodes sequentially. /// Chooses nodes sequentially.
/// ///

View File

@ -1,19 +1,11 @@
#[macro_use] #![deny(rust_2018_idioms)]
extern crate futures; #![allow(elided_lifetimes_in_paths)]
#[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;
#[cfg(test)] #[cfg(test)]
extern crate quickcheck; extern crate quickcheck;
use futures::{Async, Poll}; use futures::{Async, Poll};
use indexmap::IndexMap; use indexmap::IndexMap;
use log::{debug, trace};
use rand::{rngs::SmallRng, SeedableRng}; use rand::{rngs::SmallRng, SeedableRng};
use std::fmt; use std::fmt;
use tower_discover::Discover; use tower_discover::Discover;
@ -28,13 +20,16 @@ pub mod pool;
#[cfg(test)] #[cfg(test)]
mod test; mod test;
pub use self::choose::Choose; pub use self::{
pub use self::load::weight::{HasWeight, Weight, Weighted, WithWeighted}; choose::Choose,
pub use self::load::Load; load::{
pub use self::pool::Pool; weight::{HasWeight, Weight, Weighted, WithWeighted},
Load,
},
pool::Pool,
};
use self::error::Error; use self::{error::Error, future::ResponseFuture};
use self::future::ResponseFuture;
/// Balances requests across a set of inner services. /// Balances requests across a set of inner services.
#[derive(Debug)] #[derive(Debug)]
@ -168,7 +163,7 @@ where
self.discover.poll().map_err(|e| error::Balance(e.into()))? self.discover.poll().map_err(|e| error::Balance(e.into()))?
{ {
match change { match change {
Insert(key, mut svc) => { Insert(key, svc) => {
// If the `Insert`ed service is a duplicate of a service already // If the `Insert`ed service is a duplicate of a service already
// in the ready list, remove the ready service first. The new // in the ready list, remove the ready service first. The new
// service will then be inserted into the not-ready list. // service will then be inserted into the not-ready list.

View File

@ -1,8 +1,8 @@
use futures::{Async, Poll}; use futures::{try_ready, Async, Poll};
use tower_discover::{Change, Discover}; use tower_discover::{Change, Discover};
use tower_service::Service; use tower_service::Service;
use Load; use crate::Load;
/// Wraps a type so that `Load::load` returns a constant value. /// Wraps a type so that `Load::load` returns a constant value.
pub struct Constant<T, M> { pub struct Constant<T, M> {

View File

@ -1,4 +1,4 @@
use futures::{Future, Poll}; use futures::{try_ready, Future, Poll};
/// Attaches `I`-typed instruments to `V` typed values. /// Attaches `I`-typed instruments to `V` typed values.
/// ///

View File

@ -4,10 +4,12 @@ pub mod peak_ewma;
pub mod pending_requests; pub mod pending_requests;
pub(crate) mod weight; pub(crate) mod weight;
pub use self::constant::Constant; pub use self::{
pub use self::instrument::{Instrument, InstrumentFuture, NoInstrument}; constant::Constant,
pub use self::peak_ewma::{PeakEwma, WithPeakEwma}; instrument::{Instrument, InstrumentFuture, NoInstrument},
pub use self::pending_requests::{PendingRequests, WithPendingRequests}; peak_ewma::{PeakEwma, WithPeakEwma},
pending_requests::{PendingRequests, WithPendingRequests},
};
/// Exposes a load metric. /// Exposes a load metric.
/// ///

View File

@ -1,14 +1,17 @@
use futures::{Async, Poll}; use futures::{try_ready, Async, Poll};
use std::ops; use log::trace;
use std::sync::{Arc, Mutex}; use std::{
use std::time::{Duration, Instant}; ops,
sync::{Arc, Mutex},
time::{Duration, Instant},
};
use tokio_timer::clock; use tokio_timer::clock;
use tower_discover::{Change, Discover}; use tower_discover::{Change, Discover};
use tower_service::Service; use tower_service::Service;
use super::{Instrument, InstrumentFuture, NoInstrument}; use super::{Instrument, InstrumentFuture, NoInstrument};
use {HasWeight, Load, Weight}; use crate::{HasWeight, Load, Weight};
/// Wraps an `S`-typed Service with Peak-EWMA load measurement. /// Wraps an `S`-typed Service with Peak-EWMA load measurement.
/// ///
@ -307,14 +310,13 @@ fn nanos(d: Duration) -> f64 {
#[cfg(test)] #[cfg(test)]
mod tests { 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 futures::{future, Future, Poll};
use std::sync::{Arc, Mutex}; use std::{
use std::time::{Duration, Instant}; sync::{Arc, Mutex},
time::{Duration, Instant},
};
use tokio_executor::enter;
use tokio_timer::clock;
use super::*; use super::*;

View File

@ -1,11 +1,10 @@
use futures::{Async, Poll}; use futures::{try_ready, Async, Poll};
use std::ops; use std::{ops, sync::Arc};
use std::sync::Arc;
use tower_discover::{Change, Discover}; use tower_discover::{Change, Discover};
use tower_service::Service; use tower_service::Service;
use super::{Instrument, InstrumentFuture, NoInstrument}; use super::{Instrument, InstrumentFuture, NoInstrument};
use {HasWeight, Load, Weight}; use crate::{HasWeight, Load, Weight};
/// Expresses load based on the number of currently-pending requests. /// Expresses load based on the number of currently-pending requests.
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,9 +1,9 @@
use futures::{Async, Poll}; use futures::{try_ready, Async, Poll};
use std::ops; use std::ops;
use tower_discover::{Change, Discover}; use tower_discover::{Change, Discover};
use tower_service::Service; use tower_service::Service;
use Load; use crate::Load;
/// A weight on [0.0, ∞]. /// A weight on [0.0, ∞].
/// ///

View File

@ -15,7 +15,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use super::{Balance, Choose}; use super::{Balance, Choose};
use futures::{Async, Future, Poll}; use futures::{try_ready, Async, Future, Poll};
use tower_discover::{Change, Discover}; use tower_discover::{Change, Discover};
use tower_service::Service; use tower_service::Service;
use tower_util::MakeService; use tower_util::MakeService;

View File

@ -3,6 +3,7 @@ name = "tower-buffer"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1.25" futures = "0.1.25"
@ -12,4 +13,5 @@ tokio-executor = "0.1.7"
tokio-sync = "0.1.0" tokio-sync = "0.1.0"
[dev-dependencies] [dev-dependencies]
tower = { version = "0.1", path = "../tower" }
tower-test = { version = "0.1", path = "../tower-test" } tower-test = { version = "0.1", path = "../tower-test" }

View File

@ -1,7 +1,6 @@
//! Error types //! Error types
use std::fmt; use std::{fmt, sync::Arc};
use std::sync::Arc;
/// An error produced by a `Service` wrapped by a `Buffer` /// An error produced by a `Service` wrapped by a `Buffer`
#[derive(Debug)] #[derive(Debug)]
@ -22,7 +21,7 @@ pub struct SpawnError {
} }
/// Errors produced by `Buffer`. /// Errors produced by `Buffer`.
pub(crate) type Error = Box<::std::error::Error + Send + Sync>; pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;
// ===== impl ServiceError ===== // ===== impl ServiceError =====

View File

@ -1,8 +1,10 @@
//! Future types //! Future types
use error::{Closed, Error}; use crate::{
error::{Closed, Error},
message,
};
use futures::{Async, Future, Poll}; use futures::{Async, Future, Poll};
use message;
/// Future eventually completed with the response to the original request. /// Future eventually completed with the response to the original request.
pub struct ResponseFuture<T> { pub struct ResponseFuture<T> {

View File

@ -1,3 +1,6 @@
#![deny(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
//! Buffer requests when the inner service is out of capacity. //! Buffer requests when the inner service is out of capacity.
//! //!
//! Buffering works by spawning a new task that is dedicated to pulling requests //! 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 //! buffer and a dedicated task, the `Buffer` layer in front of the service can
//! be `Clone` even if the inner service is not. //! 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 error;
pub mod future; pub mod future;
mod message; mod message;
mod worker; mod worker;
pub use worker::WorkerExecutor; pub use crate::worker::WorkerExecutor;
use error::Error; use crate::{error::Error, future::ResponseFuture, message::Message, worker::Worker};
use future::ResponseFuture;
use message::Message;
use worker::Worker;
use futures::Poll; use futures::Poll;
use tokio_executor::DefaultExecutor; use tokio_executor::DefaultExecutor;
use tokio_sync::mpsc; use tokio_sync::{mpsc, oneshot};
use tokio_sync::oneshot;
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;

View File

@ -1,4 +1,4 @@
use error::ServiceError; use crate::error::ServiceError;
use tokio_sync::oneshot; use tokio_sync::oneshot;
/// Message sent over buffer /// Message sent over buffer

View File

@ -1,6 +1,8 @@
use error::{Closed, Error, ServiceError, SpawnError}; use crate::{
use futures::{Async, Future, Poll, Stream}; error::{Closed, Error, ServiceError, SpawnError},
use message::Message; message::Message,
};
use futures::{try_ready, Async, Future, Poll, Stream};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use tokio_executor::TypedExecutor; use tokio_executor::TypedExecutor;
use tokio_sync::mpsc; use tokio_sync::mpsc;

View File

@ -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 futures::prelude::*;
use std::{cell::RefCell, thread};
use tokio_executor::{SpawnError, TypedExecutor}; use tokio_executor::{SpawnError, TypedExecutor};
use tower_buffer::*; use tower::{
use tower_service::*; buffer::{error, Buffer},
use tower_test::mock; Service,
};
use std::cell::RefCell; use tower_test::{assert_request_eq, mock};
use std::thread;
#[test] #[test]
fn req_and_res() { fn req_and_res() {

View File

@ -3,6 +3,7 @@ name = "tower-discover"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -1,5 +1,4 @@
use std::error::Error; use std::{error::Error, fmt};
use std::fmt;
#[derive(Debug)] #[derive(Debug)]
pub enum Never {} pub enum Never {}

View File

@ -1,3 +1,6 @@
#![deny(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
//! # Tower service discovery //! # Tower service discovery
//! //!
//! Service discovery is the automatic detection of services available to the //! 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 //! via the network; however, it is possible to discover services available in
//! other processes or even in process. //! other processes or even in process.
#[macro_use]
extern crate futures;
extern crate tower_service;
mod error; mod error;
mod list; mod list;
mod stream; mod stream;
pub use crate::list::ServiceList; pub use crate::{list::ServiceList, stream::ServiceStream};
pub use crate::stream::ServiceStream;
use futures::Poll; use futures::Poll;
use std::hash::Hash; use std::hash::Hash;

View File

@ -1,5 +1,4 @@
use crate::error::Never; use crate::{error::Never, Change, Discover};
use crate::{Change, Discover};
use futures::{Async, Poll}; use futures::{Async, Poll};
use std::iter::{Enumerate, IntoIterator}; use std::iter::{Enumerate, IntoIterator};
use tower_service::Service; use tower_service::Service;

View File

@ -1,5 +1,5 @@
use crate::{Change, Discover}; use crate::{Change, Discover};
use futures::{Async, Poll, Stream}; use futures::{try_ready, Async, Poll, Stream};
use std::hash::Hash; use std::hash::Hash;
use tower_service::Service; use tower_service::Service;

View File

@ -3,6 +3,7 @@ name = "tower-filter"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -1,7 +1,6 @@
//! Error types //! Error types
use std::error; use std::{error, fmt};
use std::fmt;
/// Error produced by `Filter` /// Error produced by `Filter`
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,6 +1,6 @@
//! Future types //! Future types
use error::{self, Error}; use crate::error::{self, Error};
use futures::{Async, Future, Poll}; use futures::{Async, Future, Poll};
use tower_service::Service; use tower_service::Service;

View File

@ -1,7 +1,9 @@
use error::{self, Error}; use crate::{
error::{self, Error},
Filter, Predicate,
};
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;
use {Filter, Predicate};
pub struct FilterLayer<U> { pub struct FilterLayer<U> {
predicate: U, predicate: U,

View File

@ -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 //! Conditionally dispatch requests to the inner service based on the result of
//! a predicate. //! a predicate.
extern crate futures;
extern crate tower_layer;
extern crate tower_service;
pub mod error; pub mod error;
pub mod future; pub mod future;
mod layer; mod layer;
mod predicate; mod predicate;
pub use layer::FilterLayer; pub use crate::{layer::FilterLayer, predicate::Predicate};
pub use predicate::Predicate;
use error::Error; use crate::{error::Error, future::ResponseFuture};
use future::ResponseFuture;
use futures::Poll; use futures::Poll;
use tower_service::Service; use tower_service::Service;

View File

@ -1,4 +1,4 @@
use error::Error; use crate::error::Error;
use futures::{Future, IntoFuture}; use futures::{Future, IntoFuture};
/// Checks a request /// Checks a request

View File

@ -1,16 +1,8 @@
extern crate futures;
extern crate tower_filter;
extern crate tower_service;
#[macro_use]
extern crate tower_test;
use futures::*; use futures::*;
use tower_filter::error::Error;
use tower_filter::Filter;
use tower_service::*;
use tower_test::mock;
use std::thread; use std::thread;
use tower_filter::{error::Error, Filter};
use tower_service::Service;
use tower_test::{assert_request_eq, mock};
#[test] #[test]
fn passthrough_sync() { fn passthrough_sync() {

View File

@ -15,6 +15,7 @@ description = """
Decorates a `Service` to allow easy composition between `Service`s. Decorates a `Service` to allow easy composition between `Service`s.
""" """
categories = ["asynchronous", "network-programming"] categories = ["asynchronous", "network-programming"]
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -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")] #![doc(html_root_url = "https://docs.rs/tower-layer/0.1.0")]
//! Layer traits and extensions. //! Layer traits and extensions.
@ -8,9 +8,6 @@
//! //!
//! A middleware implements the [`Layer`] and [`Service`] trait. //! A middleware implements the [`Layer`] and [`Service`] trait.
extern crate futures;
extern crate tower_service;
use tower_service::Service; use tower_service::Service;
/// Decorates a `Service`, transforming either the request or the response. /// Decorates a `Service`, transforming either the request or the response.

View File

@ -3,6 +3,7 @@ name = "tower-limit"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -1,5 +1,4 @@
use super::never::Never; use super::{never::Never, ConcurrencyLimit, Error};
use super::{ConcurrencyLimit, Error};
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;

View File

@ -5,7 +5,6 @@ mod layer;
mod never; mod never;
mod service; mod service;
pub use self::layer::ConcurrencyLimitLayer; pub use self::{layer::ConcurrencyLimitLayer, service::ConcurrencyLimit};
pub use self::service::ConcurrencyLimit;
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;

View File

@ -1,9 +1,8 @@
use super::future::ResponseFuture; use super::{future::ResponseFuture, Error};
use super::Error;
use tower_service::Service; use tower_service::Service;
use futures::Poll; use futures::{try_ready, Poll};
use std::sync::Arc; use std::sync::Arc;
use tokio_sync::semaphore::{self, Semaphore}; use tokio_sync::semaphore::{self, Semaphore};

View File

@ -1,14 +1,11 @@
#![deny(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
//! Limit inbound requests. //! 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 concurrency;
pub mod rate; pub mod rate;
pub use crate::concurrency::{ConcurrencyLimit, ConcurrencyLimitLayer}; pub use crate::{
pub use crate::rate::{RateLimit, RateLimitLayer}; concurrency::{ConcurrencyLimit, ConcurrencyLimitLayer},
rate::{RateLimit, RateLimitLayer},
};

View File

@ -1,6 +1,6 @@
use std::error; use std::error;
pub(crate) type Error = Box<error::Error + Send + Sync>; pub(crate) type Error = Box<dyn error::Error + Send + Sync>;
pub(crate) mod never { pub(crate) mod never {
use std::{error, fmt}; use std::{error, fmt};

View File

@ -1,5 +1,7 @@
use super::error::{never::Never, Error}; use super::{
use super::{Rate, RateLimit}; error::{never::Never, Error},
Rate, RateLimit,
};
use std::time::Duration; use std::time::Duration;
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;

View File

@ -6,6 +6,4 @@ mod layer;
mod rate; mod rate;
mod service; mod service;
pub use self::layer::RateLimitLayer; pub use self::{layer::RateLimitLayer, rate::Rate, service::RateLimit};
pub use self::rate::Rate;
pub use self::service::RateLimit;

View File

@ -1,7 +1,5 @@
use super::error::Error; use super::{error::Error, future::ResponseFuture, Rate};
use super::future::ResponseFuture; use futures::{try_ready, Future, Poll};
use super::Rate;
use futures::{Future, Poll};
use tokio_timer::{clock, Delay}; use tokio_timer::{clock, Delay};
use tower_service::Service; use tower_service::Service;

View File

@ -1,16 +1,11 @@
extern crate futures; use futures::{
extern crate tokio_mock_task; self,
extern crate tower_limit; future::{poll_fn, Future},
extern crate tower_service; };
#[macro_use] use tokio_mock_task::MockTask;
extern crate tower_test;
use tower_limit::concurrency::ConcurrencyLimit; use tower_limit::concurrency::ConcurrencyLimit;
use tower_service::Service; use tower_service::Service;
use tower_test::mock; use tower_test::{assert_request_eq, mock};
use futures::future::{poll_fn, Future};
use tokio_mock_task::MockTask;
macro_rules! assert_ready { macro_rules! assert_ready {
($e:expr) => {{ ($e:expr) => {{

View File

@ -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 futures::future;
use tokio::runtime::current_thread::Runtime;
use tokio_timer::Delay;
use tower_limit::rate::*; use tower_limit::rate::*;
use tower_service::*; use tower_service::*;
use tower_test::mock; use tower_test::{assert_request_eq, mock};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -36,7 +30,7 @@ macro_rules! assert_not_ready {
#[test] #[test]
fn reaching_capacity() { 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))); let (mut service, mut handle) = new_service(Rate::new(1, from_millis(100)));
assert_ready!(service.poll_ready()); assert_ready!(service.poll_ready());
@ -57,9 +51,7 @@ fn reaching_capacity() {
assert!(poll_request.unwrap().is_not_ready()); assert!(poll_request.unwrap().is_not_ready());
// Unlike `thread::sleep`, this advances the timer. // Unlike `thread::sleep`, this advances the timer.
rt.block_on(tokio_timer::Delay::new( rt.block_on(Delay::new(Instant::now() + Duration::from_millis(100)))
Instant::now() + Duration::from_millis(100),
))
.unwrap(); .unwrap();
let poll_ready = rt.block_on(future::lazy(|| service.poll_ready())); let poll_ready = rt.block_on(future::lazy(|| service.poll_ready()));

View File

@ -3,6 +3,7 @@ name = "tower-load-shed"
version = "0.1.0" version = "0.1.0"
authors = ["Sean McArthur <sean@seanmonstar.com>"] authors = ["Sean McArthur <sean@seanmonstar.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1.25" futures = "0.1.25"

View File

@ -2,7 +2,7 @@ use std::fmt;
use futures::{Future, Poll}; use futures::{Future, Poll};
use error::{Error, Overloaded}; use crate::error::{Error, Overloaded};
/// Future for the `LoadShed` service. /// Future for the `LoadShed` service.
pub struct ResponseFuture<F> { pub struct ResponseFuture<F> {

View File

@ -1,8 +1,10 @@
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;
use error::{Error, Never}; use crate::{
use LoadShed; error::{Error, Never},
LoadShed,
};
/// A `tower-layer` to wrap services in `LoadShed` middleware. /// A `tower-layer` to wrap services in `LoadShed` middleware.
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,13 +1,11 @@
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(warnings))]
#![deny(missing_debug_implementations)] #![deny(missing_debug_implementations)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
//! tower-load-shed //! tower-load-shed
extern crate futures;
extern crate tower_layer;
extern crate tower_service;
use futures::Poll; use futures::Poll;
use tower_service::Service; use tower_service::Service;
@ -16,8 +14,7 @@ mod future;
mod layer; mod layer;
use self::error::Error; use self::error::Error;
pub use self::future::ResponseFuture; pub use self::{future::ResponseFuture, layer::LoadShedLayer};
pub use self::layer::LoadShedLayer;
/// A `Service` that sheds load when the inner service isn't ready. /// A `Service` that sheds load when the inner service isn't ready.
#[derive(Debug)] #[derive(Debug)]

View File

@ -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 futures::Future;
use tower_load_shed::LoadShed; use tower_load_shed::{self, LoadShed};
use tower_service::Service; use tower_service::Service;
use tower_test::mock; use tower_test::{assert_request_eq, mock};
#[test] #[test]
fn when_ready() { fn when_ready() {

View File

@ -3,6 +3,7 @@ name = "tower-reconnect"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
log = "0.4.1" log = "0.4.1"

View File

@ -1,5 +1,5 @@
use crate::Error;
use futures::{Future, Poll}; use futures::{Future, Poll};
use Error;
pub struct ResponseFuture<F> { pub struct ResponseFuture<F> {
inner: F, inner: F,

View File

@ -1,19 +1,15 @@
extern crate futures; #![deny(rust_2018_idioms)]
#[macro_use] #![allow(elided_lifetimes_in_paths)]
extern crate log;
extern crate tower_service;
extern crate tower_util;
pub mod future; pub mod future;
use crate::future::ResponseFuture; use crate::future::ResponseFuture;
use futures::{Async, Future, Poll}; use futures::{Async, Future, Poll};
use log::trace;
use std::fmt;
use tower_service::Service; use tower_service::Service;
use tower_util::MakeService; use tower_util::MakeService;
use std::fmt;
pub struct Reconnect<M, Target> pub struct Reconnect<M, Target>
where where
M: Service<Target>, M: Service<Target>,
@ -23,7 +19,7 @@ where
target: Target, target: Target,
} }
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug)] #[derive(Debug)]
enum State<F, S> { enum State<F, S> {

View File

@ -3,6 +3,7 @@ name = "tower-retry"
version = "0.1.0" version = "0.1.0"
authors = ["Sean McArthur <sean@seanmonstar.com>"] authors = ["Sean McArthur <sean@seanmonstar.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -1,12 +1,13 @@
//! A retry "budget" for allowing only a certain amount of retries over time. //! A retry "budget" for allowing only a certain amount of retries over time.
use std::fmt; use std::{
use std::sync::{ fmt,
sync::{
atomic::{AtomicIsize, Ordering}, atomic::{AtomicIsize, Ordering},
Mutex, Mutex,
},
time::{Duration, Instant},
}; };
use std::time::{Duration, Instant};
use tokio_timer::clock; use tokio_timer::clock;
/// Represents a "budget" for retrying requests. /// Represents a "budget" for retrying requests.
@ -212,12 +213,13 @@ impl Bucket {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate tokio_executor;
use self::tokio_executor::enter; use self::tokio_executor::enter;
use super::*; use super::*;
use std::sync::{Arc, Mutex, MutexGuard}; use std::{
use std::time::Instant; sync::{Arc, Mutex, MutexGuard},
time::Instant,
};
use tokio_executor;
#[test] #[test]
fn empty() { fn empty() {

View File

@ -1,23 +1,19 @@
#![deny(missing_debug_implementations)] #![deny(missing_debug_implementations)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![deny(warnings)] #![deny(warnings)]
#![deny(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
//! Tower middleware for retrying "failed" requests. //! Tower middleware for retrying "failed" requests.
#[macro_use] use futures::{try_ready, Async, Future, Poll};
extern crate futures;
extern crate tokio_timer;
extern crate tower_layer;
extern crate tower_service;
use futures::{Async, Future, Poll};
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;
pub mod budget; pub mod budget;
mod never; mod never;
use never::Never; use crate::never::Never;
/// A "retry policy" to classify if a request should be retried. /// A "retry policy" to classify if a request should be retried.
/// ///

View File

@ -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 futures::{future, Future};
use tower_retry::Policy; use tower_retry::Policy;
use tower_service::Service; use tower_service::Service;
use tower_test::mock; use tower_test::{assert_request_eq, mock};
#[test] #[test]
fn retry_errors() { fn retry_errors() {
@ -83,7 +77,7 @@ fn success_with_cannot_clone() {
type Req = &'static str; type Req = &'static str;
type Res = &'static str; type Res = &'static str;
type InnerError = &'static str; type InnerError = &'static str;
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
type Mock = mock::Mock<Req, Res>; type Mock = mock::Mock<Req, Res>;
type Handle = mock::Handle<Req, Res>; type Handle = mock::Handle<Req, Res>;

View File

@ -3,6 +3,7 @@ name = "tower-test"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -1,8 +1,7 @@
//! Mock `Service` that can be used in tests. #![deny(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
extern crate futures; //! Mock `Service` that can be used in tests.
extern crate tokio_sync;
extern crate tower_service;
mod macros; mod macros;
pub mod mock; pub mod mock;

View File

@ -1,9 +1,8 @@
//! Error types //! Error types
use std::error; use std::{error, fmt};
use std::fmt;
pub(crate) type Error = Box<error::Error + Send + Sync>; pub(crate) type Error = Box<dyn error::Error + Send + Sync>;
#[derive(Debug)] #[derive(Debug)]
pub struct Closed(()); pub struct Closed(());

View File

@ -1,6 +1,6 @@
//! Future types //! Future types
use super::error::{self, Error}; use crate::mock::error::{self, Error};
use futures::{Async, Future, Poll}; use futures::{Async, Future, Poll};
use tokio_sync::oneshot; use tokio_sync::oneshot;

View File

@ -3,16 +3,19 @@
pub mod error; pub mod error;
pub mod future; pub mod future;
use self::error::Error; use crate::mock::{error::Error, future::ResponseFuture};
use self::future::ResponseFuture; use futures::{
use futures::task::{self, Task}; task::{self, Task},
use futures::{Async, Future, Poll, Stream}; Async, Future, Poll, Stream,
};
use tokio_sync::{mpsc, oneshot}; use tokio_sync::{mpsc, oneshot};
use tower_service::Service; use tower_service::Service;
use std::collections::HashMap; use std::{
use std::sync::{Arc, Mutex}; collections::HashMap,
use std::u64; sync::{Arc, Mutex},
u64,
};
/// A mock service /// A mock service
#[derive(Debug)] #[derive(Debug)]

View File

@ -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 futures::Future;
use tower_service::Service;
use tower_test::{assert_request_eq, mock};
#[test] #[test]
fn single_request_ready() { fn single_request_ready() {

View File

@ -3,6 +3,7 @@ name = "tower-timeout"
version = "0.1.0" version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"] authors = ["Carl Lerche <me@carllerche.com>"]
publish = false publish = false
edition = "2018"
[dependencies] [dependencies]
futures = "0.1" futures = "0.1"

View File

@ -2,7 +2,7 @@
use std::{error, fmt}; use std::{error, fmt};
pub(crate) type Error = Box<error::Error + Send + Sync>; pub(crate) type Error = Box<dyn error::Error + Send + Sync>;
/// The timeout elapsed. /// The timeout elapsed.
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,5 +1,4 @@
use crate::{Error, Timeout}; use crate::{never::Never, Error, Timeout};
use never::Never;
use std::time::Duration; use std::time::Duration;
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;

View File

@ -4,14 +4,10 @@
//! will be aborted. //! will be aborted.
#![doc(html_root_url = "https://docs.rs/tower-timeout/0.1.0")] #![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))] #![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 error;
pub mod future; pub mod future;
mod layer; mod layer;
@ -19,8 +15,7 @@ mod never;
pub use crate::layer::TimeoutLayer; pub use crate::layer::TimeoutLayer;
use crate::error::Error; use crate::{error::Error, future::ResponseFuture};
use crate::future::ResponseFuture;
use futures::Poll; use futures::Poll;
use tokio_timer::{clock, Delay}; use tokio_timer::{clock, Delay};

View File

@ -17,6 +17,7 @@ description = """
Utilities for working with tower-service. Utilities for working with tower-service.
""" """
categories = ["asynchronous", "network-programming"] categories = ["asynchronous", "network-programming"]
edition = "2018"
[features] [features]
io = ["tokio-io"] io = ["tokio-io"]

View File

@ -58,5 +58,4 @@
mod sync; mod sync;
mod unsync; mod unsync;
pub use self::sync::BoxService; pub use self::{sync::BoxService, unsync::UnsyncBoxService};
pub use self::unsync::UnsyncBoxService;

View File

@ -11,14 +11,14 @@ use std::fmt;
/// ///
/// See module level documentation for more details. /// See module level documentation for more details.
pub struct BoxService<T, U, E> { pub struct BoxService<T, U, E> {
inner: Box<Service<T, Response = U, Error = E, Future = BoxFuture<U, E>> + Send>, inner: Box<dyn Service<T, Response = U, Error = E, Future = BoxFuture<U, E>> + Send>,
} }
/// A boxed `Future + Send` trait object. /// A boxed `Future + Send` trait object.
/// ///
/// This type alias represents a boxed future that is `Send` and can be moved /// This type alias represents a boxed future that is `Send` and can be moved
/// across threads. /// across threads.
type BoxFuture<T, E> = Box<Future<Item = T, Error = E> + Send>; type BoxFuture<T, E> = Box<dyn Future<Item = T, Error = E> + Send>;
#[derive(Debug)] #[derive(Debug)]
struct Boxed<S> { struct Boxed<S> {
@ -68,7 +68,7 @@ where
{ {
type Response = S::Response; type Response = S::Response;
type Error = S::Error; type Error = S::Error;
type Future = Box<Future<Item = S::Response, Error = S::Error> + Send>; type Future = Box<dyn Future<Item = S::Response, Error = S::Error> + Send>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.inner.poll_ready() self.inner.poll_ready()

View File

@ -5,14 +5,14 @@ use std::fmt;
/// A boxed `Service` trait object. /// A boxed `Service` trait object.
pub struct UnsyncBoxService<T, U, E> { pub struct UnsyncBoxService<T, U, E> {
inner: Box<Service<T, Response = U, Error = E, Future = UnsyncBoxFuture<U, E>>>, inner: Box<dyn Service<T, Response = U, Error = E, Future = UnsyncBoxFuture<U, E>>>,
} }
/// A boxed `Future` trait object. /// A boxed `Future` trait object.
/// ///
/// This type alias represents a boxed future that is *not* `Send` and must /// This type alias represents a boxed future that is *not* `Send` and must
/// remain on the current thread. /// remain on the current thread.
type UnsyncBoxFuture<T, E> = Box<Future<Item = T, Error = E>>; type UnsyncBoxFuture<T, E> = Box<dyn Future<Item = T, Error = E>>;
#[derive(Debug)] #[derive(Debug)]
struct UnsyncBoxed<S> { struct UnsyncBoxed<S> {
@ -62,7 +62,7 @@ where
{ {
type Response = S::Response; type Response = S::Response;
type Error = S::Error; type Error = S::Error;
type Future = Box<Future<Item = S::Response, Error = S::Error>>; type Future = Box<dyn Future<Item = S::Response, Error = S::Error>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.inner.poll_ready() self.inner.poll_ready()

View File

@ -4,7 +4,6 @@ mod common;
mod ordered; mod ordered;
mod unordered; mod unordered;
pub use self::ordered::CallAll; pub use self::{ordered::CallAll, unordered::CallAllUnordered};
pub use self::unordered::CallAllUnordered;
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;

View File

@ -1,8 +1,7 @@
//! `Stream<Item = Request>` + `Service<Request>` => `Stream<Item = Response>`. //! `Stream<Item = Request>` + `Service<Request>` => `Stream<Item = Response>`.
use super::{common, Error}; use super::{common, Error};
use futures::stream::FuturesOrdered; use futures::{stream::FuturesOrdered, Future, Poll, Stream};
use futures::{Future, Poll, Stream};
use tower_service::Service; use tower_service::Service;
/// This is a `futures::Stream` of responses resulting from calling the wrapped `tower::Service` /// This is a `futures::Stream` of responses resulting from calling the wrapped `tower::Service`

View File

@ -1,8 +1,7 @@
//! `Stream<Item = Request>` + `Service<Request>` => `Stream<Item = Response>`. //! `Stream<Item = Request>` + `Service<Request>` => `Stream<Item = Response>`.
use super::{common, Error}; use super::{common, Error};
use futures::stream::FuturesUnordered; use futures::{stream::FuturesUnordered, Future, Poll, Stream};
use futures::{Future, Poll, Stream};
use tower_service::Service; use tower_service::Service;
/// A stream of responses received from the inner service in received order. /// A stream of responses received from the inner service in received order.

View File

@ -15,7 +15,7 @@ pub enum Either<A, B> {
B(B), B(B),
} }
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
impl<A, B, Request> Service<Request> for Either<A, B> impl<A, B, Request> Service<Request> for Either<A, B>
where where

View File

@ -1,5 +1,4 @@
mod chain; mod chain;
mod identity; mod identity;
pub use self::chain::Chain; pub use self::{chain::Chain, identity::Identity};
pub use self::identity::Identity;

View File

@ -1,11 +1,6 @@
//! Various utility types and functions that are generally with Tower. //! Various utility types and functions that are generally with Tower.
#![deny(rust_2018_idioms)]
#[macro_use] #![allow(elided_lifetimes_in_paths)]
extern crate futures;
#[cfg(feature = "io")]
extern crate tokio_io;
extern crate tower_layer;
extern crate tower_service;
mod boxed; mod boxed;
mod call_all; mod call_all;
@ -20,16 +15,18 @@ mod ready;
mod sealed; mod sealed;
mod service_fn; mod service_fn;
pub use crate::boxed::{BoxService, UnsyncBoxService};
pub use crate::call_all::{CallAll, CallAllUnordered};
pub use crate::either::Either;
#[cfg(feature = "io")] #[cfg(feature = "io")]
pub use crate::make_connection::MakeConnection; pub use crate::make_connection::MakeConnection;
pub use crate::make_service::MakeService; pub use crate::{
pub use crate::oneshot::Oneshot; boxed::{BoxService, UnsyncBoxService},
pub use crate::optional::Optional; call_all::{CallAll, CallAllUnordered},
pub use crate::ready::Ready; either::Either,
pub use crate::service_fn::ServiceFn; make_service::MakeService,
oneshot::Oneshot,
optional::Optional,
ready::Ready,
service_fn::ServiceFn,
};
pub mod error { pub mod error {
//! Error types //! Error types

View File

@ -1,10 +1,9 @@
use std::error; use std::{error, fmt};
use std::fmt;
#[derive(Debug)] #[derive(Debug)]
pub struct None(()); pub struct None(());
pub(crate) type Error = Box<error::Error + Send + Sync>; pub(crate) type Error = Box<dyn error::Error + Send + Sync>;
impl None { impl None {
pub(crate) fn new() -> None { pub(crate) fn new() -> None {

View File

@ -6,8 +6,7 @@
pub mod error; pub mod error;
pub mod future; pub mod future;
use self::error::Error; use self::{error::Error, future::ResponseFuture};
use self::future::ResponseFuture;
use futures::Poll; use futures::Poll;
use tower_service::Service; use tower_service::Service;

View File

@ -1,7 +1,6 @@
use std::fmt; use std::{fmt, marker::PhantomData};
use std::marker::PhantomData;
use futures::{Future, Poll}; use futures::{try_ready, Future, Poll};
use tower_service::Service; use tower_service::Service;
/// Future yielding a `Service` once the service is ready to process a request /// Future yielding a `Service` once the service is ready to process a request

View File

@ -1,21 +1,14 @@
extern crate futures; use futures::{
extern crate tokio_mock_task; self,
extern crate tower; future::{ok, FutureResult},
extern crate tower_service; stream, Async, Poll, Stream,
#[macro_use] };
extern crate tower_test; use std::{cell::Cell, rc::Rc};
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 tower::ServiceExt; use tower::ServiceExt;
use tower_service::*; 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<dyn std::error::Error + Send + Sync>;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
struct Srv { struct Srv {

View File

@ -12,6 +12,7 @@ clients and servers.
""" """
categories = ["asynchronous", "network-programming"] categories = ["asynchronous", "network-programming"]
keywords = ["io", "async", "non-blocking", "futures", "service"] keywords = ["io", "async", "non-blocking", "futures", "service"]
edition = "2018"
[features] [features]
default = ["full"] default = ["full"]

View File

@ -9,28 +9,18 @@
#![deny(warnings)] #![deny(warnings)]
extern crate futures; use env_logger;
extern crate futures_cpupool; use futures::{
extern crate tokio_timer; future::{Executor, FutureResult},
extern crate tower; sync::{mpsc, oneshot},
extern crate tower_service; Async, Future, IntoFuture, Poll, Stream,
};
#[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 futures_cpupool::CpuPool; use futures_cpupool::CpuPool;
use log::info;
use tokio_timer::Timer; use tokio_timer::Timer;
use tower::{MakeService, Service, ServiceExt};
use std::io; use std::{io, time::Duration};
use std::time::Duration;
/// Service that dispatches requests to a side task using a channel. /// Service that dispatches requests to a side task using a channel.
#[derive(Debug)] #[derive(Debug)]

View File

@ -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 futures::Future;
use hyper::client::connect::Destination; use hyper::{
use hyper::client::HttpConnector; client::{connect::Destination, HttpConnector},
use hyper::{Request, Response, Uri}; Request, Response, Uri,
};
use std::time::Duration; use std::time::Duration;
use tower::builder::ServiceBuilder; use tower::{builder::ServiceBuilder, reconnect::Reconnect, Service, ServiceExt};
use tower::ServiceExt; use tower_hyper::{
use tower_buffer::BufferLayer; client::{Builder, Connect},
use tower_hyper::client::{Builder, Connect}; retry::{Body, RetryPolicy},
use tower_hyper::retry::{Body, RetryPolicy}; util::Connector,
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;
fn main() { fn main() {
let fut = futures::lazy(|| { let fut = futures::lazy(|| {
@ -49,11 +35,11 @@ fn request() -> impl Future<Item = Response<hyper::Body>, Error = ()> {
// - meet `RetryLayer`'s requirement that our service implement `Service + Clone` // - meet `RetryLayer`'s requirement that our service implement `Service + Clone`
// - ..and to provide cheap clones on the service. // - ..and to provide cheap clones on the service.
let maker = ServiceBuilder::new() let maker = ServiceBuilder::new()
.layer(BufferLayer::new(5)) .buffer(5)
.layer(RateLimitLayer::new(5, Duration::from_secs(1))) .rate_limit(5, Duration::from_secs(1))
.layer(ConcurrencyLimitLayer::new(5)) .concurrency_limit(5)
.layer(RetryLayer::new(policy)) .retry(policy)
.layer(BufferLayer::new(5)) .buffer(5)
.make_service(hyper); .make_service(hyper);
// `Reconnect` accepts a destination and a MakeService, creating a new service // `Reconnect` accepts a destination and a MakeService, creating a new service

View File

@ -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 futures::{future, Future, Poll, Stream};
use hyper::{Body, Request, Response}; use hyper::{self, Body, Request, Response};
use tokio_tcp::TcpListener; use tokio_tcp::TcpListener;
use tower::builder::ServiceBuilder; use tower::{builder::ServiceBuilder, Service};
use tower_hyper::body::LiftBody; use tower_hyper::{body::LiftBody, server::Server};
use tower_hyper::server::Server;
use tower_limit::concurrency::ConcurrencyLimitLayer;
use tower_service::Service;
fn main() { fn main() {
hyper::rt::run(future::lazy(|| { hyper::rt::run(future::lazy(|| {
@ -23,7 +12,7 @@ fn main() {
println!("Listening on http://{}", addr); println!("Listening on http://{}", addr);
let maker = ServiceBuilder::new() let maker = ServiceBuilder::new()
.layer(ConcurrencyLimitLayer::new(5)) .concurrency_limit(5)
.make_service(MakeSvc); .make_service(MakeSvc);
let server = Server::new(maker); let server = Server::new(maker);
@ -67,7 +56,7 @@ struct MakeSvc;
impl Service<()> for MakeSvc { impl Service<()> for MakeSvc {
type Response = Svc; type Response = Svc;
type Error = hyper::Error; type Error = hyper::Error;
type Future = Box<Future<Item = Self::Response, Error = Self::Error> + Send + 'static>; type Future = Box<dyn Future<Item = Self::Response, Error = Self::Error> + Send + 'static>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(().into()) Ok(().into())

View File

@ -4,21 +4,24 @@ mod service;
pub use self::service::{LayeredMakeService, ServiceFuture}; pub use self::service::{LayeredMakeService, ServiceFuture};
use buffer::BufferLayer; use crate::{
use limit::concurrency::ConcurrencyLimitLayer; buffer::BufferLayer,
use limit::rate::RateLimitLayer; limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer},
use load_shed::LoadShedLayer; load_shed::LoadShedLayer,
use retry::RetryLayer; retry::RetryLayer,
use timeout::TimeoutLayer; timeout::TimeoutLayer,
};
use tower_layer::Layer; use tower_layer::Layer;
use tower_service::Service; use tower_service::Service;
use tower_util::layer::{Chain, Identity}; use tower_util::{
use tower_util::MakeService; layer::{Chain, Identity},
MakeService,
};
use std::time::Duration; use std::time::Duration;
pub(super) type Error = Box<::std::error::Error + Send + Sync>; pub(super) type Error = Box<dyn std::error::Error + Send + Sync>;
/// Declaratively construct Service values. /// Declaratively construct Service values.
/// ///

View File

@ -1,10 +1,9 @@
use super::Error; use super::Error;
use futures::{Async, Future, Poll}; use crate::Service;
use std::marker::PhantomData; use futures::{try_ready, Async, Future, Poll};
use std::sync::Arc; use std::{marker::PhantomData, sync::Arc};
use tower_layer::Layer; use tower_layer::Layer;
use tower_util::MakeService; use tower_util::MakeService;
use Service;
/// Composed `MakeService` produced from `ServiceBuilder` /// Composed `MakeService` produced from `ServiceBuilder`
#[derive(Debug)] #[derive(Debug)]

View File

@ -2,9 +2,9 @@
pub use tower_layer::Layer; pub use tower_layer::Layer;
/// `util` exports an Identity Layer and Chain, a mechanism for chaining them.
pub mod util { pub mod util {
pub use tower_util::layer::Chain; pub use tower_util::layer::{Chain, Identity};
pub use tower_util::layer::Identity;
} }
/// An extension trait for `Layer`'s that provides a variety of convenient /// An extension trait for `Layer`'s that provides a variety of convenient

View File

@ -1,30 +1,22 @@
// Allows refining features in the future without breaking backwards // Allows refining features in the future without breaking backwards
// compatibility // compatibility
#![cfg(feature = "full")] #![cfg(feature = "full")]
#![deny(missing_docs, rust_2018_idioms)]
//! Various utility types and functions that are generally with Tower. //! Various utility types and functions that are generally with Tower.
#[macro_use] pub use tower_buffer as buffer;
extern crate futures; pub use tower_discover as discover;
pub use tower_limit as limit;
extern crate tower_layer; pub use tower_load_shed as load_shed;
extern crate tower_service; pub use tower_reconnect as reconnect;
extern crate tower_util; pub use tower_retry as retry;
pub use tower_timeout as timeout;
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 mod builder; pub mod builder;
pub mod layer; pub mod layer;
pub mod util; pub mod util;
pub use builder::ServiceBuilder; pub use crate::{builder::ServiceBuilder, util::ServiceExt};
pub use tower_service::Service; pub use tower_service::Service;
pub use tower_util::MakeConnection; pub use tower_util::{MakeConnection, MakeService};
pub use tower_util::MakeService;
pub use util::ServiceExt;

View File

@ -1,21 +1,15 @@
//! Combinators for working with `Service`s //! 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 futures::Stream;
use tower_service::Service; use tower_service::Service;
pub use tower_util::{
BoxService, CallAll, CallAllUnordered, Either, Oneshot, Optional, Ready, ServiceFn,
UnsyncBoxService,
};
impl<T: ?Sized, Request> ServiceExt<Request> for T where T: Service<Request> {} impl<T: ?Sized, Request> ServiceExt<Request> for T where T: Service<Request> {}
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
/// An extension trait for `Service`s that provides a variety of convenient /// An extension trait for `Service`s that provides a variety of convenient
/// adapters /// adapters

View File

@ -1,20 +1,11 @@
extern crate futures; use futures::{
extern crate tokio; future::{self, FutureResult},
extern crate tower; prelude::*,
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 std::time::Duration; use std::time::Duration;
use tower::builder::ServiceBuilder; use tower::builder::ServiceBuilder;
use tower_buffer::BufferLayer; use tower_buffer::BufferLayer;
use tower_limit::concurrency::ConcurrencyLimitLayer; use tower_limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer};
use tower_limit::rate::RateLimitLayer;
use tower_reconnect::Reconnect; use tower_reconnect::Reconnect;
use tower_retry::{Policy, RetryLayer}; use tower_retry::{Policy, RetryLayer};
use tower_service::*; use tower_service::*;
@ -121,7 +112,7 @@ struct MockPolicy;
impl<E> Policy<Request, Response, E> for MockPolicy impl<E> Policy<Request, Response, E> for MockPolicy
where where
E: Into<Box<std::error::Error + Send + Sync + 'static>>, E: Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
{ {
type Future = FutureResult<Self, ()>; type Future = FutureResult<Self, ()>;