This is a major breaking release including a large number of changes. In
particular, this release updates tower
to depend on Tokio 1.0, and moves all
middleware into the tower
crate. In addition, Tower 0.4 reworks several
middleware APIs, as well as introducing new ones.
This release does not change the core Service
or Layer
traits, so tower
0.4 still depends on tower-service
0.3 and tower-layer
0.3. This means that
tower
0.4 is still compatible with libraries that depend on those crates.
Added
- make: Added
MakeService::into_service
andMakeService::as_service
for
convertingMakeService
s intoService
s (#492) - steer: Added
steer
middleware for routing requests to one of a set of
services (#426) - util: Added
MapRequest
middleware andServiceExt::map_request
, for
applying a function to a request before passing it to the inner service
(#435) - util: Added
MapResponse
middleware andServiceExt::map_response
, for
applying a function to theResponse
type of an inner service after its
future completes (#435) - util: Added
MapErr
middleware andServiceExt::map_err
, for
applying a function to theError
returned by an inner service if it fails
(#396) - util: Added
MapResult
middleware andServiceExt::map_result
, for
applying a function to theResult
returned by an inner service's future
regardless of whether it succeeds or fails (#499) - util: Added
Then
middleware andServiceExt::then
, for chaining another
future after an inner service's future completes (with aResponse
or an
Error
) (#500) - util: Added
AndThen
middleware andServiceExt::and_then
, for
chaining another future after an inner service's future completes successfully
(#485) - util: Added
layer_fn
, for constructing aLayer
from a function taking
aService
and returning a differentService
(#491) - util: Added
FutureService
, which implementsService
for a
Future
whoseOutput
type is aService
([#496]) - util: Added
BoxService::layer
andUnsyncBoxService::layer
, to make
constructing layers more ergonomic (#503) - layer: Added
Layer
impl for&Layer
(#446) - retry: Added
Retry::get_ref
,Retry::get_mut
, andRetry::into_inner
to access the inner service (#463) - timeout: Added
Timeout::get_ref
,Timeout::get_mut
, and
Timeout::into_inner
to access the inner service (#463) - buffer: Added
Clone
andCopy
impls forBufferLayer
(#493) - Several documentation improvements (#442, #444, #445, #449, #487,
#490, #506])
Changed
- All middleware
tower-*
crates were merged intotower
and placed
behind feature flags (#432) - Updated Tokio dependency to 1.0 (#489)
- builder: Make
ServiceBuilder::service
takeself
by reference rather
than by value (#504) - reconnect: Return errors from
MakeService
in the response future, rather than
inpoll_ready
, allowing the reconnect service to be reused when a reconnect
fails (#386, #437) - discover: Changed
Discover
to be a sealed trait alias for a
TryStream<Item = Change>
.Discover
implementations are now written by
implementingStream
. (#443) - load: Renamed the
Instrument
trait toTrackCompletion
(#445) - load: Renamed
NoInstrument
toCompleteOnResponse
(#445) - balance: Renamed
BalanceLayer
toMakeBalanceLayer
(#449) - balance: Renamed
BalanceMake
toMakeBalance
(#449) - ready-cache: Changed
ready_cache::error::Failed
'sfmt::Debug
impl to
require the key type to also implementfmt::Debug
(#467) - filter: Changed
Filter
andPredicate
to use a synchronous function as
a predicate (#508) - filter: Renamed the previous
Filter
andPredicate
(wherePredicate
s
returned aFuture
) toAsyncFilter
andAsyncPredicate
(#508) - filter:
Predicate
s now take aRequest
type by value and may return a
new request, potentially of a different type (#508) - filter:
Predicate
s may now return an error of any type (#508)
Fixed
- limit: Fixed an issue where
RateLimit
services do not reset the remaining
count when rate limiting (#438, [#439]) - util: Fixed a bug where
oneshot
futures panic if the service does not
immediately become ready (#447) - ready-cache: Fixed
ready_cache::error::Failed
not returning inner error types
viaError::source
(#467) - hedge: Fixed an interaction with
buffer
wherebuffer
slots were
eagerly reserved for hedge requests even if they were not sent (#472) - hedge: Fixed the use of a fixed 10 second bound on the hedge latency
histogram resulting on errors with longer-lived requests. The latency
histogram now automatically resizes (#484) - buffer: Fixed an issue where tasks waiting for buffer capacity were not
woken when a buffer is dropped, potentially resulting in a task leak (#480)