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"
authors = ["Carl Lerche <me@carllerche.com>"]
publish = false
edition = "2018"
[dependencies]
futures = "0.1"

View File

@ -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<dyn std::error::Error + Send + Sync>;
fn gen_disco() -> impl Discover<
Key = usize,

View File

@ -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<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 {
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;
fn index(&self, idx: usize) -> &Self::Output {

View File

@ -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].
///

View File

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

View File

@ -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.

View File

@ -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<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.
///

View File

@ -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.
///

View File

@ -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::*;

View File

@ -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)]

View File

@ -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, ∞].
///

View File

@ -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;

View File

@ -3,6 +3,7 @@ name = "tower-buffer"
version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"]
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" }

View File

@ -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<dyn std::error::Error + Send + Sync>;
// ===== impl ServiceError =====

View File

@ -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<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.
//!
//! 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;

View File

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

View File

@ -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;

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 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() {

View File

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

View File

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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

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

View File

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

View File

@ -1,6 +1,6 @@
//! Future types
use error::{self, Error};
use crate::error::{self, Error};
use futures::{Async, Future, Poll};
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_service::Service;
use {Filter, Predicate};
pub struct FilterLayer<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
//! 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;

View File

@ -1,4 +1,4 @@
use error::Error;
use crate::error::Error;
use futures::{Future, IntoFuture};
/// 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 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() {

View File

@ -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"

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")]
//! 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.

View File

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

View File

@ -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;

View File

@ -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<dyn std::error::Error + Send + Sync>;

View File

@ -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};

View File

@ -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},
};

View File

@ -1,6 +1,6 @@
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 {
use std::{error, fmt};

View File

@ -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;

View File

@ -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};

View File

@ -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;

View File

@ -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) => {{

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 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);

View File

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

View File

@ -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<F> {

View File

@ -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)]

View File

@ -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)]

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 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() {

View File

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

View File

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

View File

@ -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<M, Target>
where
M: Service<Target>,
@ -23,7 +19,7 @@ where
target: Target,
}
type Error = Box<::std::error::Error + Send + Sync>;
type Error = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug)]
enum State<F, S> {

View File

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

View File

@ -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() {

View File

@ -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.
///

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 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<dyn std::error::Error + Send + Sync>;
type Mock = mock::Mock<Req, Res>;
type Handle = mock::Handle<Req, Res>;

View File

@ -3,6 +3,7 @@ name = "tower-test"
version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"]
publish = false
edition = "2018"
[dependencies]
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;
extern crate tokio_sync;
extern crate tower_service;
//! Mock `Service` that can be used in tests.
mod macros;
pub mod mock;

View File

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

View File

@ -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;

View File

@ -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)]

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

View File

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

View File

@ -2,7 +2,7 @@
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.
#[derive(Debug)]

View File

@ -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;

View File

@ -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};

View File

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

View File

@ -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};

View File

@ -11,14 +11,14 @@ use std::fmt;
///
/// See module level documentation for more details.
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.
///
/// This type alias represents a boxed future that is `Send` and can be moved
/// 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)]
struct Boxed<S> {
@ -68,7 +68,7 @@ where
{
type Response = S::Response;
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> {
self.inner.poll_ready()

View File

@ -5,14 +5,14 @@ use std::fmt;
/// A boxed `Service` trait object.
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.
///
/// This type alias represents a boxed future that is *not* `Send` and must
/// 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)]
struct UnsyncBoxed<S> {
@ -62,7 +62,7 @@ where
{
type Response = S::Response;
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> {
self.inner.poll_ready()

View File

@ -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<dyn std::error::Error + Send + Sync>;

View File

@ -1,8 +1,7 @@
//! `Stream<Item = Request>` + `Service<Request>` => `Stream<Item = Response>`.
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`

View File

@ -1,8 +1,7 @@
//! `Stream<Item = Request>` + `Service<Request>` => `Stream<Item = Response>`.
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.

View File

@ -15,7 +15,7 @@ pub enum Either<A, 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>
where

View File

@ -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};

View File

@ -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

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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<dyn std::error::Error + Send + Sync>;
#[derive(Debug, Eq, PartialEq)]
struct Srv {

View File

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

View File

@ -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)]

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 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<Item = Response<hyper::Body>, 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

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 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<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> {
Ok(().into())

View File

@ -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<dyn std::error::Error + Send + Sync>;
/// Declaratively construct Service values.
///

View File

@ -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)]

View File

@ -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

View File

@ -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};

View File

@ -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<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
/// adapters

View File

@ -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<E> Policy<Request, Response, E> for MockPolicy
where
E: Into<Box<std::error::Error + Send + Sync + 'static>>,
E: Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
{
type Future = FutureResult<Self, ()>;