185 Commits

Author SHA1 Message Date
Eliza Weisman aeabc2bc02 chore: prepare to release tower v0.4.13 (#672)
# 0.4.13 (June 17, 2022)

### Added

- **load_shed**: Public constructor for `Overloaded` error ([#661])

### Fixed

- **util**: Fix hang with `call_all` when the `Stream` of requests is
  pending ([#656])
- **ready_cache**: Ensure cancelation is observed by pending services
  ([#668], fixes [#415])
- **docs**: Fix a missing section header due to a typo ([#646])
- **docs**: Fix broken links to `Service` trait ([#659])

[#661]: https://github.com/tower-rs/tower/pull/661
[#656]: https://github.com/tower-rs/tower/pull/656
[#668]: https://github.com/tower-rs/tower/pull/668
[#415]: https://github.com/tower-rs/tower/pull/415
[#646]: https://github.com/tower-rs/tower/pull/646
[#659]: https://github.com/tower-rs/tower/pull/659
2022-06-17 19:36:31 +00:00
Oliver Gould 4236b5a668 ready-cache: Ensure cancelation can be observed (#668)
`tokio::task` enforces a cooperative scheduling regime that can cause
`oneshot::Receiver::poll` to return pending after the sender has sent an
update. `ReadyCache` uses a oneshot to notify pending services that they
should not become ready. When a cancelation is not observed, the ready
cache return service instances that should have been canceled, which
breaks assumptions and causes an invalid state.

This branch replaces the use of `tokio::sync::oneshot` for canceling 
pending futures with a custom cancelation handle using an `AtomicBool`
and `futures::task::AtomicWaker`. This ensures that canceled `Pending`
services are always woken even when the task's budget is exceeded.
Additionally, cancelation status is now always known to the `Pending`
future, by checking the `AtomicBool` immediately on polls, even in cases
where the canceled `Pending` future was woken by the inner `Service`
becoming ready, rather than by the cancelation.

Fixes #415

Signed-off-by: Oliver Gould <ver@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2022-06-17 12:18:32 -07:00
Eliza Weisman 3512f39797 ready_cache: just use pin_project for Pending (#667)
This gets rid of the `Unpin` impl with the weird comment on it.

Alternatively, we could just put a `S: Unpin` bound on `Pending`, but
this changes the public API to require that the service type is `Unpin`.
In practice, it will be, but we could also just avoid the trait bound.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-06-17 12:18:32 -07:00
Matt Klein 42dded33e5 load_shed: make constructor for Overloaded error public (#661)
This allows for mocking. This also matches what is done for
the timeout Elapsed error.

Signed-off-by: Matt Klein <mklein@lyft.com>
2022-06-17 12:18:32 -07:00
Leonardo Yvens 50df08ed40 util: Fix call_all hang when stream is pending (#656)
Currently `call_all` will hang in a busy loop if called when the input
stream is pending.
2022-06-17 12:18:32 -07:00
Grachev Mikhail f7a768f8f6 tower: fix docs typo (#646) 2022-06-17 12:18:32 -07:00
Eliza Weisman e4e6e0f4c7 ci: run MSRV checks with minimal dep versions (#670)
In many cases, new releases of a dependency can break compatibility with
Tower's minimum supported Rust version (MSRV). It shouldn't be necessary
for Tower to bump its MSRV when a dependency does, as users on older
Rust versions should be able to depend on older versions of that crate.
Instead, we should probably just run our MSRV checks with minimal
dependency versions.

This branch changes Tower's CI jobs to do that. It was also necessary to 
make some changes to the `Cargo.toml` to actually fix the build with
minimal dependency versions.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-06-17 11:24:25 -07:00
Eliza Weisman 2401e4d94f chore: prepare to release tower v0.4.12 (#642)
* chore: prepare to release v0.4.12

# 0.4.12 (February 16, 2022)

### Fixed

- **hedge**, **load**, **retry**: Fix use of `Instant` operations that
  can panic on platforms where `Instant` is not monotonic ([#633])
- Disable `attributes` feature on `tracing` dependency ([#623])
- Remove unused dependencies and dependency features with some feature
  combinations ([#603], [#602])
- **docs**: Fix a typo in the RustDoc for `Buffer` ([#622])

### Changed

- Updated minimum supported Rust version (MSRV) to 1.49.0.
- **hedge**: Updated `hdrhistogram` dependency to v7.0 ([#602])
- Updated `tokio-util` dependency to v0.7 ([#638])

[#633]: https://github.com/tower-rs/tower/pull/633
[#623]: https://github.com/tower-rs/tower/pull/623
[#603]: https://github.com/tower-rs/tower/pull/603
[#602]: https://github.com/tower-rs/tower/pull/602
[#622]: https://github.com/tower-rs/tower/pull/622
[#638]: https://github.com/tower-rs/tower/pull/638

* add msrv
2022-02-16 22:42:08 +00:00
Eliza Weisman ac85986808 chore: bump MSRV to 1.49.0 (#645)
`tower` builds are now failing on CI because Tokio v1.17.0 bumped MSRV
to 1.49.0. This branch updates `tower`'s MSRV to 1.49.0 to track Tokio's
MSRV. I also added nicer documentation of the MSRV based on Tokio's, and
added the `rust-version` Cargo metadata to the `tower` crate's
`Cargo.toml`.

Note that `tower-service` and `tower-layer` can technically continue to
support much earlier Rust versions than `tower` can, since they don't
depend on external crates and are very small. We could consider testing
separate, older MSRVs on CI for those crates individually. I didn't do
that in this PR, though, because I wasn't sure if this was worth the
effort and I just wanted to get CI passing again.
2022-02-16 13:14:05 -08:00
Eliza Weisman e057f33845 tower: update tokio-util to v0.7 (#638)
This PR updates `tokio-util` to v0.7.

It also updates the minimum `tokio` dependency to v1.6.0.
This is because `tokio-util` requires at least `tokio` v1.6.0 for
`mpsc::Sender::reserve_owned`, but it only specifies a minimum version
of v1.0.0. This is incorrect and should be considered an upstream bug,
but updating our tokio dep fixes this, so that should at least unbreak
`tower`'s build for now.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-02-11 11:29:57 -08:00
Eliza Weisman f95a4a9c01 tower: fix annoying clippy lints (#639)
This fixes a bunch of minor clippy lints. None of them were particularly
major, but I was getting tired of the warnings showing up in vscode.

The one lint that had to be ignored rather than fixed is the
`clippy::bool_assert_comparison` lint, which triggers on the
`tower_test::assert_request_eq!` macro. The lint triggers when writing
code like `assert_eq!(whatever, true)` rather than simply
`assert!(whatever)`. In this case, this occurs because the macro makes
an assertion about a request value, and in _some_ tests, the request
type is `bool`. We can't change this to use `assert!`, because in most
cases, when the request is not `bool`, we actually do need `assert_eq!`,
so I ignored that warning.
2022-02-11 11:11:15 -08:00
Oliver Gould 32032ceb90 Avoid time operations that can panic
We have reports of runtime panics (linkerd/linkerd2#7748) that sound a
lot like rust-lang/rust#86470. We don't have any evidence that these
panics originate in tower, but we have some potentialy flawed `Instant`
arithmetic that could panic in this way.

Even though this is almost definitely a bug in Rust, it seems most
prudent to actively avoid the uses of `Instant` that are prone to this
bug.

This change replaces uses of `Instant::elapsed` and `Instant::sub` with
calls to `Instant::saturating_duration_since` to prevent this class of
panic. These fixes should ultimately be made in the standard library,
but this change lets us avoid this problem while we wait for those
fixes.

See also hyperium/hyper#2746
2022-01-31 16:23:47 -08:00
Christian Legnitto 5ee3c3461e chore: Update links to layer list in README (#627)
Previous links were broken. These now link to https://docs.rs/tower/latest/tower/#modules.

Co-authored-by: Oliver Gould <ver@buoyant.io>
2022-01-18 08:08:23 +01:00
Jonas Platte 2c57e6afb6 Fix sometimes-unused dependencies (#603)
`tower` currently has required dependencies that may not be used
unless certain features are enabled.

This change updates `tower` to make these dependencies optional.

Furthermore, this change removes use of `html_root_url`, which is no
longer recommended (https://github.com/rust-lang/api-guidelines/pull/230),
and updates the documented release instructions.
2022-01-17 15:25:07 -08:00
Paolo Barbolini 5f0431ce83 Import tracing without the attributes feature (#623)
tracing-attributes depends on syn and proc-macro2, which are slow to compile
2021-12-29 09:47:08 -08:00
Sibi Prabakaran 4a6aab2493 Minor doc fix for buffer function (#622) 2021-12-24 10:55:07 +01:00
Oliver Gould 4306c5ce0f Assert that no unsafe code is used in tower (#621)
The tower crates do not include any `unsafe` code, but tools like
[`cargo-geiger`][cg] can't necessarily detect that. This change adds a
stronger assertion at the top of each crate with a
`#![forbid(unsafe_code)]` directive to assert that no unsafe code is
used in the crate. This also serves as a more obvious obstacle to
introducing unsafe code in future changes.

[cg]: https://github.com/rust-secure-code/cargo-geiger
2021-11-24 15:26:16 -08:00
Qinxuan Chen 37ff641cf4 tower: update hdrhistogram to 7.0 and remove useless dependencies (#620)
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
2021-11-19 10:12:48 +01:00
David Pedersen f8a8055268 tower: prepare to release 0.4.11 (#618)
* tower: prepare to release 0.4.11

Added

- **util**: Add `CloneBoxService` which is a `Clone + Send` boxed `Service` ([#615])
- **util**: Add `ServiceExt::boxed` and `ServiceExt::clone_boxed` for applying the
  `BoxService` and `CloneBoxService` middleware ([#616])
- **builder**: Add `ServiceBuilder::boxed` and `ServiceBuilder::clone_boxed` for
  applying `BoxService` and `CloneBoxService` layers ([#616])

Fixed

- **balance**: Remove redundant `Req: Clone` bound from `Clone` impls
  for `MakeBalance`, and `MakeBalanceLayer` ([#607])
- **balance**: Remove redundant `Req: Debug` bound from `Debug` impls
  for `MakeBalance`, `MakeFuture`, `Balance`, and `Pool` ([#607])
- **ready-cache**: Remove redundant `Req: Debug` bound from `Debug` impl
  for `ReadyCache` ([#607])
- **steer**: Remove redundant `Req: Debug` bound from `Debug` impl
  for `Steer` ([#607])
- **util**: Remove redundant `F: Clone` bound
  from `ServiceExt::map_request` ([#607])
- **docs**: Fix `doc(cfg(...))` attributes
  of `PeakEwmaDiscover`, and `PendingRequestsDiscover` ([#610])
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for BoxService` ([#617])
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for UnsyncBoxService` ([#617])

[#607]: https://github.com/tower-rs/tower/pull/607
[#610]: https://github.com/tower-rs/tower/pull/610
[#616]: https://github.com/tower-rs/tower/pull/616
[#617]: https://github.com/tower-rs/tower/pull/617
[#615]: https://github.com/tower-rs/tower/pull/615

* sorting

* Rename `CloneBoxService` to `BoxCloneService`

* formatting

* also update changelog
2021-11-18 20:40:01 +01:00
David Pedersen acb98e3661 builder,util: add convenience methods for boxing services (#616)
* builder,util: add convenience methods for boxing services

This adds a couple of new methods to `ServiceBuilder` and `ServiceExt`:

- `ServiceBuilder::boxed`
- `ServiceExt::boxed`
- `ServiceBuilder::clone_boxed`
- `ServiceExt::clone_boxed`

They apply `BoxService::layer` and `CloneBoxService::layer`
respectively.

* fix doc links

* add missing `cfg`s

* Update tower/CHANGELOG.md

Co-authored-by: Eliza Weisman <eliza@buoyant.io>

* Apply suggestions from code review

Co-authored-by: Eliza Weisman <eliza@buoyant.io>

* not sure why rustdoc cannot infer these

* line breaks

* trailing whitespace

* make docs a bit more consistent

* fix doc links

* update tokio

* don't pull in old version of tower

* Don't run `cargo deny check bans` as it hangs

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-11-18 13:56:19 +01:00
David Pedersen 145d7fe0fd util: remove unnecessary Debug bounds from boxed services (#617) 2021-11-11 21:59:29 +01:00
David Pedersen 87a2caef00 util: add CloneBoxService (#615)
* util: add `CloneService`

This upstreams a little utility I'm using a bunch in axum. Its often
useful to erase the type of a service while still being able to clone
it.

`BoxService` isn't `Clone` previously you had to combine it with
`Buffer` but doing that a lot (which we did in axum) had measurable
impact on performance.

* Address review feedback

* remove needless trait bounds
2021-11-09 21:39:27 +01:00
cppforliving 62724a07f5 docs: Fix doc(cfg(...)) attributes (#610) (#610)
`RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --all-features` outputs some warnings
```
warning: unused attribute `doc`
  --> tower/src/load/peak_ewma.rs:52:20
   |
52 | #[cfg_attr(docsrs, doc(cfg(feature = "discover")))]
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_attributes)]` on by default
note: the built-in attribute `doc` will be ignored, since it's applied to the macro invocation `pin_project`
  --> tower/src/load/peak_ewma.rs:53:1
   |
53 | pin_project! {
   | ^^^^^^^^^^^

warning: unused attribute `doc`
  --> tower/src/load/pending_requests.rs:31:20
   |
31 | #[cfg_attr(docsrs, doc(cfg(feature = "discover")))]
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the built-in attribute `doc` will be ignored, since it's applied to the macro invocation `pin_project`
  --> tower/src/load/pending_requests.rs:32:1
   |
32 | pin_project! {
   | ^^^^^^^^^^^

warning: `tower` (lib doc) generated 2 warnings
```

This PR is an attempt to fix this.
2021-11-09 09:26:57 -08:00
Folyd db5fa0ede2 docs: Replace ready_and() with ready() in docs (#611) 2021-11-02 15:19:50 +01:00
cppforliving b8ec83a974 Remove redundant Clone, and Debug bounds (#607)
The balancer types derive `Debug` and `Clone` implementations, but
this unnecessarily requires that its type parameters implement these
traits.

This change provides manual implementations for `Clone` and `Debug`
to avoid this unintentional restriction.

Closes #606
2021-10-27 22:33:39 -07:00
David Pedersen 8c0b55d1c8 tower: prepare to release 0.4.10 (#608)
* tower: prepare to release 0.4.10

- Fix accidental breaking change when using the
  `rustdoc::broken_intra_doc_links` lint ([#605])
- Clarity that tower's minimum supported rust version is 1.46 ([#605])

[#605]: https://github.com/tower-rs/tower/pull/605

* Update tower/CHANGELOG.md

Co-authored-by: Oliver Gould <ver@buoyant.io>

Co-authored-by: Oliver Gould <ver@buoyant.io>
2021-10-19 21:56:23 +02:00
David Pedersen d61227c09b chore: Bump MSRV to 1.46 (#605)
* Actually check MSCV on CI

* check broken_intra_doc_links on CI

* clean up CI

* fix other crates

* bump MSRV to 1.42 because of tracing-core

* attempt to fix http not working on 1.42

* use `--workspace` instead of `--all`

`--all` is deprecated

* make tower-service build on 1.42

* force http version 0.2.4

* actually msrv is 1.46 because of tokio

* fix running `cargo fmt`

* clean up

* also run tests on 1.46

* ignore rustsec in time
2021-10-19 16:28:55 +02:00
David Pedersen 42407f4a1d tower: prepare to release 0.4.9 (#602)
- Migrate to pin-project-lite ([#595])
- **builder**: Implement `Layer` for `ServiceBuilder` ([#600])
- **builder**: Add `ServiceBuilder::and_then` analogous to
  `ServiceExt::and_then` ([#601])

[#600]: https://github.com/tower-rs/tower/pull/600
[#601]: https://github.com/tower-rs/tower/pull/601
[#595]: https://github.com/tower-rs/tower/pull/595
[pin-project-lite]: https://crates.io/crates/pin-project-lite
2021-10-14 09:12:28 +02:00
David Pedersen 7cc4066877 builder: Add ServiceBuilder::and_then (#601)
This one was missing.

Was the only combinator from `ServiceExt` that wasn't on
`ServiceBuilder` so now they match.
2021-09-04 13:05:46 -07:00
David Pedersen a108f87721 builder: Implement Layer for ServiceBuilder (#600) 2021-09-03 18:54:49 +02:00
David Pedersen dbfa760669 util: Refactor BoxService (#598) 2021-08-26 06:54:29 +02:00
Michael-J-Ward bb1633f1aa Migrate to pin project lite (#595)
* REMOVE ME updates peak_wema test to pass

* adds pin_project_lite dependency

* uses pin_project_lite for load::Constant

* uses pin_project_lite for load::PencingRequestsDiscover

* uses pin_project_lite for load::PeakEwma

* uses pin_project_lite for load::Completion

* uses pin_project_lite for tests::support::IntoStream

Turns IntoStream into a regular struct because pin_project_lite does not and will support tuple structs.

https://github.com/taiki-e/pin-project-lite/blob/416be96f7777862c68b567c92a91887f69a8c2b3/src/lib.rs#L401-L408

* refactors opaque_future into a regular struct

This enables migration to pin_project_lite, which does not and will not support tuple structs
https://github.com/taiki-e/pin-project-lite/blob/416be96f7777862c68b567c92a91887f69a8c2b3/src/lib.rs#L401-L408

* migrates opaque_future to use pin_project_lite

* removes tuple variant from load_shed::ResponseState enum

* migrates load_shed::future to pin_project_lite

* removes tuple variant from filter::future::State

* migrates filter::future to pin_project_lite

Note: the doc comment on AsyncResponseFuture::service was also reduced to a regular comment.

This is a known limitation of pin_project_lite that the they have labeled as "help wanted".
https://github.com/taiki-e/pin-project-lite/issues/3#issuecomment-745194112

* migrates retry::Retry to pin_project_lite

* refactors retry::future::State to enable pin_project_lite

pin_project_lite has the current limitation of nto supporting doc comments
https://github.com/taiki-e/pin-project-lite/issues/3#issuecomment-745194112

pin_project_lite does not and will not support tuple variants
https://github.com/taiki-e/pin-project-lite/blob/416be96f7777862c68b567c92a91887f69a8c2b3/src/lib.rs#L401-L408

* migrates retry::future to pin_project_lite

* migrates spawn_ready::make to pin_project_lite

* refactors buffer::future::ResponseState to allow pin_project_lite

* migrates buffer::future to pin_project_lite

* refactors util::AndThenFuture to allow pin_project_lite

* migrates util::AndThenFuture to pin_project_lite

* migrates hedge::Future to pin_project_lite

* migrates hedge::select::ResponseFuture to pin_project_lite

* refactors hedge::delay enum for pin_project_lite

* refactors reconnect::future enum for pin_project_lite

* refactors oneshot::State enum for pin_project_lite

* migrates util::oneshot to pin_project_lite

* migrates reconnect::future to pin_project_lite

* migrates hedge::delay to pin_project_lite

* migrates hedge::latency to pin_project_lite

* migrates discover::list to pin_project_lite

* migrates timeout::future to pin_project_lite

* migrates balance::pool to pin_project_lite

* migrates balance::p2c::make to pin_project_lite

* migrates balance::p2c::service to pin_project_lite

* migrates call_all::ordered to pin_project_lite

* migrates call_all::common to pin_project_lite

* migrates call_all::unordered to pin_project_lite

* migrates util::optional::future to pin_project_lite

* migrates limit::concurrency::future to pin_project_lite

* migrates tower-balance example to pin_project_lite

* applies cargo fmt

* migrates tower-test to pin_project_lite

* fixes cargo hack check

peak_wma and pending_requests will now properly compile without the "discover" feature enabled.

* fixes lint rename warning on nightly

broken_intra_doc_links has been renamed to rustdoc::broken_intra_doc_links

* migrates buffer::Worker to pin_project_lite

pin_project_lite does support PinnedDrop
https://github.com/taiki-e/pin-project-lite/pull/25/files

However, it does not support generic trait bounds on the PinnedDrop impl.

To workaround this, I removed the T::Error bound from the Worker struct definition,
and moved `close_semaphore` to a a new impl without that trait bound.

* fixes abort_on_drop test

This test was also failing on master.

* applies cargo fmt
2021-07-28 13:48:47 -04:00
kazk ea63ebb5df Add kube to the list of libraries (#592) 2021-06-06 08:54:21 +02:00
David Pedersen 31da2911ed tower: prepare to release 0.4.8 (#591) 2021-05-28 22:18:09 +02:00
Jerome Gravel-Niquet 1544bbf260 Allow reusable concurrency limit via GlobalConcurrencyLimit (#574)
* limit: global concurrency limit layer from a owned semaphore

* new_owned -> new_shared + docs improvements

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* keep exposing Semaphore, but rename the API a bit and make it simpler to use

* missed a spot

* minor docs fixes

* update changelog

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-05-28 16:45:44 +02:00
Lucio Franco 8f00201560 Fix warning in oneshot test (#587)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-05-18 16:31:29 -04:00
David Pedersen 5a9f8cd8d0 docs: Add "Inventing the Service trait" guide (#585)
This adds the first Tower guide called "Inventing the `Service` trait". It attempts to motivate all the parts to `Service` by walking the user through how they could have invented `Service` themselves, from scratch. It goes into quite a bit of detail but hopefully it paints a somewhat complete picture in the end.

The next guide I want to write is about how to implement a proper `Timeout` middleware using `Layer`, pin-project, and all the bells and whistles.

Ref: https://github.com/tower-rs/tower/issues/33
2021-05-14 22:59:43 +02:00
David Pedersen 7f212512ea builder: Add ServiceBuilder::map_result (#583)
Noticed that `ServiceBuilder` didn't have `map_result`, only `then`
which is async.
2021-05-07 09:42:31 -07:00
Eliza Weisman edfe5a5fe3 tower: prepare to release 0.4.7 (#582)
# 0.4.7 (April 27, 2021)

### Added

- **builder**: Add `ServiceBuilder::check_service` to check the request,
    response, and error types of the output service. ([#576])
- **builder**: Add `ServiceBuilder::check_service_clone` to check the
  output service can be cloned. ([#576])

### Fixed

- **spawn_ready**: Abort spawned background tasks when the `SpawnReady`
  service is dropped, fixing a potential task/resource leak (#[581])
- Fixed broken documentation links ([#578])

[#576]: https://github.com/tower-rs/tower/pull/576
[#578]: https://github.com/tower-rs/tower/pull/578
[#581]: https://github.com/tower-rs/tower/pull/581
2021-04-27 12:59:57 -07:00
Oliver Gould 3fffe1310f spawn-ready: Abort background tasks when the service is dropped (#581)
The `SpawnReady` service spawns a background task whenever the inner
service is not ready; but when the `SpawnReady` service is dropped, this
task continues to run until it becomes ready (at which point the ready
service will be dropped). This can cause resource leaks when the inner
service never becomes ready.

This change adds a `Drop` implementation for the `SpawnReady` service
that aborts the background task when one is present.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-04-27 10:26:07 -07:00
Michał Zabielski 40800ab8d5 chore: add explicit feature flag for tower-balance example (#580) 2021-04-22 16:38:58 -04:00
Folyd c32f7318a7 chore: convert rest doc-links to intra-doc links (#578) 2021-04-21 13:02:58 +02:00
David Pedersen 10e184754a builder: Add type check utility methods (#576) 2021-04-08 23:39:15 +02:00
Eliza Weisman e6f256d82c tower: prepare to release v0.4.6 (#573)
Deprecated

- **util**: Deprecated `ServiceExt::ready_and` (renamed to
  `ServiceExt::ready`). ([#567])
- **util**: Deprecated `ReadyAnd` future (renamed to `Ready`). ([#567])

Added

- **builder**: Add `ServiceBuilder::layer_fn` to add a layer built from
  a function. ([#560])
- **builder**: Add `ServiceBuilder::map_future` for transforming the
  futures produced by a service. ([#559])
- **builder**: Add `ServiceBuilder::service_fn` for applying `Layer`s to
  an async function using `util::service_fn`. ([#564])
- **util**: Add example for `service_fn`. ([#563])
- **util**: Add `BoxLayer` for creating boxed `Layer` trait objects.
  ([#569])

[#567]: https://github.com/tower-rs/tower/pull/567
[#560]: https://github.com/tower-rs/tower/pull/560
[#559]: https://github.com/tower-rs/tower/pull/559
[#564]: https://github.com/tower-rs/tower/pull/564
[#563]: https://github.com/tower-rs/tower/pull/563
[#569]: https://github.com/tower-rs/tower/pull/569

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-03-01 09:32:29 -08:00
David Pedersen a4f947fabc util: Add BoxLayer (#569)
I've run into a use case where I need to return a `Layer` with a complex
type from a function. I previously used `impl Layer<S, Service = impl
Service<...>>` but that impacted compile times quite significantly.
Boxing the `Layer` fixed it. Thought it made sense to upstream.

The `Send + Sync + 'static` bounds on the inner `dyn Layer` were
necessary to get it working with hyper.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-02-26 15:35:47 -08:00
David Pedersen 5c63ab8f73 builder: Add ServiceBuilder::service_fn (#564)
* builder: Add `ServiceBuilder::service_fn`

A small convenience for doing `.service(service_fn(handler_function))`.

* Docs tweaks

* Apply suggestions from code review

Co-authored-by: Eliza Weisman <eliza@buoyant.io>

* Fix

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-02-25 22:52:37 +01:00
David Pedersen df5774e76c builder: Add ServiceBuilder::layer_fn (#560)
This gem as just [sitting in Tonic][sit] waiting to be upstreamed.

[sit]: https://github.com/hyperium/tonic/blob/master/tonic/src/transport/service/layer.rs

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-02-25 22:33:35 +01:00
David Barsky 05ff82abe8 chore: remove unnecessary mut and imports in tests (#570)
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-02-25 16:19:59 -05:00
David Pedersen c3788f818d util: Add example for service_fn (#563) 2021-02-25 10:17:37 -08:00
David Barsky 2d74a2a78b util: Rename ServiceExt::ready_and to ServiceExt::ready (#567)
This PR renames: 

- `ServiceExt::ready_and` to `ServiceExt::ready`
- the `ReadyAnd` future to `Ready`
- the associated documentation to refer to `ServiceExt::ready`
  and `ReadyAnd`.

This PR deprecates:

- the `ServiceExt::ready_and` method
- the `ReadyAnd` future

These can be removed in Tower 0.5.

My recollection of the original conversation surrounding the
introduction of the `ServiceExt::ready_and` combinator in
https://github.com/tower-rs/tower/pull/427 was that it was meant to be a
temporary workaround for the unchainable `ServiceExt::ready` combinator
until the next breaking release of the Tower crate. The unchainable
`ServiceExt::ready` combinator was removed, but `ServiceExt::ready_and`
was not renamed. I believe, but am not 100% sure, that this was an
oversight.
2021-02-25 09:37:45 -08:00